Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e2d6fb9

Browse files
committed
Make paths oart of containers
1 parent a40efd2 commit e2d6fb9

1 file changed

Lines changed: 28 additions & 26 deletions

File tree

lib/matplotlib/collections.py

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def __init__(
4141
self.edgecolors = edgecolors
4242
self.facecolors = facecolors
4343
self.hatchcolors = hatchcolors
44+
self.paths = None
4445

4546
def describe(self):
4647
return {
@@ -52,6 +53,7 @@ def describe(self):
5253
"facecolors": Desc(("N",), "data"),
5354
"hatchcolors": Desc(("N",), "data"),
5455
"transforms": Desc(("N", 3, 3), "data"),
56+
"paths": Desc(("N",), "path"),
5557
}
5658

5759
def query(self, graph, parent_coordinates="axes"):
@@ -63,6 +65,7 @@ def query(self, graph, parent_coordinates="axes"):
6365
"facecolors": self.facecolors,
6466
"hatchcolors": self.hatchcolors,
6567
"transforms": transforms,
68+
"paths": self.paths,
6669
}
6770
return d, ""
6871
# TODO hash
@@ -396,7 +399,6 @@ def __init__(self, *,
396399

397400
self._path_effects = None
398401
self._internal_update(kwargs)
399-
self._paths = None
400402

401403
def _init_container(self):
402404
return CollectionContainer(
@@ -408,10 +410,10 @@ def _init_container(self):
408410
)
409411

410412
def get_paths(self):
411-
return self._paths
413+
return self._container.paths
412414

413415
def set_paths(self, paths):
414-
self._paths = paths
416+
self._container.paths = paths
415417
self.stale = True
416418

417419
def get_transforms(self):
@@ -1354,7 +1356,7 @@ def __init__(self, paths, sizes=None, **kwargs):
13541356
self.stale = True
13551357

13561358
def get_paths(self):
1357-
return self._paths
1359+
return self._container.paths
13581360

13591361
def legend_elements(self, prop="colors", num="auto",
13601362
fmt=None, func=lambda x: x, **kwargs):
@@ -1544,7 +1546,7 @@ def set_verts(self, verts, closed=True):
15441546

15451547
# No need to do anything fancy if the path isn't closed.
15461548
if not closed:
1547-
self._paths = [mpath.Path(xy) for xy in verts]
1549+
self._container.paths = [mpath.Path(xy) for xy in verts]
15481550
return
15491551

15501552
# Fast path for arrays
@@ -1555,16 +1557,16 @@ def set_verts(self, verts, closed=True):
15551557
template_path = mpath.Path(verts_pad[0], closed=True)
15561558
codes = template_path.codes
15571559
_make_path = mpath.Path._fast_from_codes_and_verts
1558-
self._paths = [_make_path(xy, codes, internals_from=template_path)
1559-
for xy in verts_pad]
1560+
self._container.paths = [_make_path(xy, codes, internals_from=template_path)
1561+
for xy in verts_pad]
15601562
return
15611563

1562-
self._paths = []
1564+
self._container.paths = []
15631565
for xy in verts:
15641566
if len(xy):
1565-
self._paths.append(mpath.Path._create_closed(xy))
1567+
self._container.paths.append(mpath.Path._create_closed(xy))
15661568
else:
1567-
self._paths.append(mpath.Path(xy))
1569+
self._container.paths.append(mpath.Path(xy))
15681570

15691571
set_paths = set_verts
15701572

@@ -1573,7 +1575,7 @@ def set_verts_and_codes(self, verts, codes):
15731575
if len(verts) != len(codes):
15741576
raise ValueError("'codes' must be a 1D list or array "
15751577
"with the same length of 'verts'")
1576-
self._paths = [mpath.Path(xy, cds) if len(xy) else mpath.Path(xy)
1578+
self._container.paths = [mpath.Path(xy, cds) if len(xy) else mpath.Path(xy)
15771579
for xy, cds in zip(verts, codes)]
15781580
self.stale = True
15791581

@@ -1865,7 +1867,7 @@ def __init__(self,
18651867
self._container.rotation = rotation
18661868
self._numsides = numsides
18671869
self.set_transform(transforms.IdentityTransform())
1868-
self._paths = [self._path_generator(numsides)]
1870+
self._container.paths = [self._path_generator(numsides)]
18691871

18701872
def _init_container(self):
18711873
return RegularPolyCollectionContainer(
@@ -1962,9 +1964,9 @@ def set_segments(self, segments):
19621964
if segments is None:
19631965
return
19641966

1965-
self._paths = [mpath.Path(seg) if isinstance(seg, np.ma.MaskedArray)
1966-
else mpath.Path(np.asarray(seg, float))
1967-
for seg in segments]
1967+
self._container.paths = [mpath.Path(seg) if isinstance(seg, np.ma.MaskedArray)
1968+
else mpath.Path(np.asarray(seg, float))
1969+
for seg in segments]
19681970
self.stale = True
19691971

19701972
set_verts = set_segments # for compatibility with PolyCollection
@@ -1980,7 +1982,7 @@ def get_segments(self):
19801982
"""
19811983
segments = []
19821984

1983-
for path in self._paths:
1985+
for path in self._container.paths:
19841986
vertices = [
19851987
vertex
19861988
for vertex, _
@@ -2075,7 +2077,7 @@ def _get_inverse_paths_linestyles(self):
20752077
if ls == (0, None) else
20762078
(path, mlines._get_inverse_dash_pattern(*ls))
20772079
for (path, ls) in
2078-
zip(self._paths, itertools.cycle(self._linestyles))]
2080+
zip(self._container.paths, itertools.cycle(self._linestyles))]
20792081

20802082
return zip(*path_patterns)
20812083

@@ -2280,7 +2282,7 @@ def __init__(self, sizes, **kwargs):
22802282
super().__init__(**kwargs)
22812283
self.set_sizes(sizes)
22822284
self.set_transform(transforms.IdentityTransform())
2283-
self._paths = [mpath.Path.unit_circle()]
2285+
self._container.paths = [mpath.Path.unit_circle()]
22842286

22852287

22862288
class EllipseCollection(Collection):
@@ -2313,7 +2315,7 @@ def __init__(self, widths, heights, angles, *, units='points', **kwargs):
23132315
self.set_angles(angles)
23142316
self._container.units = units
23152317
self.set_transform(transforms.IdentityTransform())
2316-
self._paths = [mpath.Path.unit_circle()]
2318+
self._container.paths = [mpath.Path.unit_circle()]
23172319

23182320
def _init_container(self):
23192321
return EllipseCollectionContainer(
@@ -2437,7 +2439,7 @@ def determine_facecolor(patch):
24372439
def set_paths(self, patches):
24382440
paths = [p.get_transform().transform_path(p.get_path())
24392441
for p in patches]
2440-
self._paths = paths
2442+
self._container.paths = paths
24412443

24422444

24432445
class TriMesh(Collection):
@@ -2460,12 +2462,12 @@ def __init__(self, triangulation, **kwargs):
24602462
self._bbox.update_from_data_xy(xy)
24612463

24622464
def get_paths(self):
2463-
if self._paths is None:
2465+
if self._container.paths is None:
24642466
self.set_paths()
2465-
return self._paths
2467+
return self._container.paths
24662468

24672469
def set_paths(self):
2468-
self._paths = self.convert_mesh_to_paths(self._triangulation)
2470+
self._container.paths = self.convert_mesh_to_paths(self._triangulation)
24692471

24702472
@staticmethod
24712473
def convert_mesh_to_paths(tri):
@@ -2703,12 +2705,12 @@ def __init__(self, coordinates, *, antialiased=True, shading='flat',
27032705
self.set_mouseover(False)
27042706

27052707
def get_paths(self):
2706-
if self._paths is None:
2708+
if self._container.paths is None:
27072709
self.set_paths()
2708-
return self._paths
2710+
return self._container.paths
27092711

27102712
def set_paths(self):
2711-
self._paths = self._convert_mesh_to_paths(self._coordinates)
2713+
self._container.paths = self._convert_mesh_to_paths(self._coordinates)
27122714
self.stale = True
27132715

27142716
def get_datalim(self, transData):

0 commit comments

Comments
 (0)