| 1298 | |
| 1299 | |
| 1300 | class PolyCollection(_CollectionWithSizes): |
| 1301 | |
| 1302 | def __init__(self, verts, sizes=None, *, closed=True, **kwargs): |
| 1303 | """ |
| 1304 | Parameters |
| 1305 | ---------- |
| 1306 | verts : list of array-like |
| 1307 | The sequence of polygons [*verts0*, *verts1*, ...] where each |
| 1308 | element *verts_i* defines the vertices of polygon *i* as a 2D |
| 1309 | array-like of shape (M, 2). |
| 1310 | sizes : array-like, default: None |
| 1311 | Squared scaling factors for the polygons. The coordinates of each |
| 1312 | polygon *verts_i* are multiplied by the square-root of the |
| 1313 | corresponding entry in *sizes* (i.e., *sizes* specify the scaling |
| 1314 | of areas). The scaling is applied before the Artist master |
| 1315 | transform. |
| 1316 | closed : bool, default: True |
| 1317 | Whether the polygon should be closed by adding a CLOSEPOLY |
| 1318 | connection at the end. |
| 1319 | **kwargs |
| 1320 | Forwarded to `.Collection`. |
| 1321 | """ |
| 1322 | super().__init__(**kwargs) |
| 1323 | self.set_sizes(sizes) |
| 1324 | self.set_verts(verts, closed) |
| 1325 | self.stale = True |
| 1326 | |
| 1327 | def set_verts(self, verts, closed=True): |
| 1328 | """ |
| 1329 | Set the vertices of the polygons. |
| 1330 | |
| 1331 | Parameters |
| 1332 | ---------- |
| 1333 | verts : list of array-like |
| 1334 | The sequence of polygons [*verts0*, *verts1*, ...] where each |
| 1335 | element *verts_i* defines the vertices of polygon *i* as a 2D |
| 1336 | array-like of shape (M, 2). |
| 1337 | closed : bool, default: True |
| 1338 | Whether the polygon should be closed by adding a CLOSEPOLY |
| 1339 | connection at the end. |
| 1340 | """ |
| 1341 | self.stale = True |
| 1342 | if isinstance(verts, np.ma.MaskedArray): |
| 1343 | verts = verts.astype(float).filled(np.nan) |
| 1344 | |
| 1345 | # No need to do anything fancy if the path isn't closed. |
| 1346 | if not closed: |
| 1347 | self._paths = [mpath.Path(xy) for xy in verts] |
| 1348 | return |
| 1349 | |
| 1350 | # Fast path for arrays |
| 1351 | if isinstance(verts, np.ndarray) and len(verts.shape) == 3 and verts.size: |
| 1352 | verts_pad = np.concatenate((verts, verts[:, :1]), axis=1) |
| 1353 | # It's faster to create the codes and internal flags once in a |
| 1354 | # template path and reuse them. |
| 1355 | template_path = mpath.Path(verts_pad[0], closed=True) |
| 1356 | codes = template_path.codes |
| 1357 | _make_path = mpath.Path._fast_from_codes_and_verts |
no outgoing calls
searching dependent graphs…