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

Skip to content

Commit 943c749

Browse files
committed
New path-related utilities (used for an aborted attempt at fixing
contouring -- may be useful in other contexts in the future). svn path=/branches/transforms/; revision=4286
1 parent 393bcbc commit 943c749

3 files changed

Lines changed: 336 additions & 16 deletions

File tree

lib/matplotlib/patches.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def set_facecolor(self, color):
152152
ACCEPTS: any matplotlib color
153153
"""
154154
self._facecolor = color
155-
155+
156156
def set_linewidth(self, w):
157157
"""
158158
Set the patch linewidth in points
@@ -522,6 +522,28 @@ def get_path(self):
522522
def get_patch_transform(self):
523523
return self._poly_transform
524524

525+
class PathPatch(Patch):
526+
"""
527+
A general polycurve path patch.
528+
"""
529+
def __str__(self):
530+
return "Poly((%g, %g) ...)" % tuple(self._path.vertices[0])
531+
532+
def __init__(self, path, **kwargs):
533+
"""
534+
path is a Path object
535+
536+
Valid kwargs are:
537+
%(Patch)s
538+
See Patch documentation for additional kwargs
539+
"""
540+
Patch.__init__(self, **kwargs)
541+
self._path = path
542+
__init__.__doc__ = cbook.dedent(__init__.__doc__) % artist.kwdocd
543+
544+
def get_path(self):
545+
return self._path
546+
525547
class Polygon(Patch):
526548
"""
527549
A general polygon patch.
@@ -549,7 +571,7 @@ def _get_xy(self):
549571
def _set_xy(self, vertices):
550572
self._path = Path(vertices)
551573
xy = property(_get_xy, _set_xy)
552-
574+
553575
class Wedge(Patch):
554576
def __str__(self):
555577
return "Wedge(%g,%g)"%self.xy[0]

lib/matplotlib/path.py

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
from matplotlib.numerix import npyma as ma
1212

1313
from matplotlib._path import point_in_path, get_path_extents, \
14-
point_in_path_collection
15-
import matplotlib._path as _path
14+
point_in_path_collection, get_path_collection_extents, \
15+
path_in_path
1616
from matplotlib.cbook import simple_linear_interpolation
1717

1818
KAPPA = 4.0 * (npy.sqrt(2) - 1) / 3.0
@@ -128,6 +128,30 @@ def __init__(self, vertices, codes=None):
128128
self.codes = codes
129129
self.vertices = vertices
130130

131+
#@staticmethod
132+
def make_compound_path(*args):
133+
"""
134+
Make a compound path from a list of Path objects. Only
135+
polygons (not curves) are supported.
136+
"""
137+
for p in args:
138+
assert p.codes is None
139+
140+
lengths = [len(x) for x in args]
141+
total_length = sum(lengths)
142+
143+
vertices = npy.vstack([x.vertices for x in args])
144+
vertices.reshape((total_length, 2))
145+
146+
codes = Path.LINETO * npy.ones(total_length)
147+
i = 0
148+
for length in lengths:
149+
codes[i] = Path.MOVETO
150+
i += length
151+
152+
return Path(vertices, codes)
153+
make_compound_path = staticmethod(make_compound_path)
154+
131155
def __repr__(self):
132156
return "Path(%s, %s)" % (self.vertices, self.codes)
133157

@@ -186,9 +210,18 @@ def contains_point(self, point, transform=None):
186210
"""
187211
if transform is None:
188212
from transforms import IdentityTransform
189-
transform = IdentityTransform
213+
transform = IdentityTransform()
190214
return point_in_path(point[0], point[1], self, transform.frozen())
191215

216+
def contains_path(self, path, transform=None):
217+
"""
218+
Returns True if this path completely contains the given path.
219+
"""
220+
if transform is None:
221+
from transforms import IdentityTransform
222+
transform = IdentityTransform()
223+
return path_in_path(self, IdentityTransform(), path, transform)
224+
192225
def get_extents(self, transform=None):
193226
"""
194227
Returns the extents (xmin, ymin, xmax, ymax) of the path.
@@ -408,8 +441,9 @@ def wedge(cls, theta1, theta2):
408441
return cls.arc(theta1, theta2, True)
409442
wedge = classmethod(wedge)
410443

444+
_get_path_collection_extents = get_path_collection_extents
411445
def get_path_collection_extents(*args):
412446
from transforms import Bbox
413447
if len(args[1]) == 0:
414448
raise ValueError("No paths provided")
415-
return Bbox.from_extents(*_path.get_path_collection_extents(*args))
449+
return Bbox.from_extents(*_get_path_collection_extents(*args))

0 commit comments

Comments
 (0)