Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

patches.polygon: fix bug in handling of path closing, #1018.

This is a modification of that pull request, with a test added.
  • Loading branch information...
commit c6cc861f3ac22a4063a52fb46c8d71fc4d7a26b9 1 parent 447a7cc
@efiring authored
View
5 CHANGELOG
@@ -1,3 +1,8 @@
+2012-08-11 Fix path-closing bug in patches.Polygon, so that regardless
+ of whether the path is the initial one or was subsequently
+ set by set_xy(), get_xy() will return a closed path if and
+ only if get_closed() is True. Thanks to Jacob Vanderplas. - EF
+
2012-08-05 When a norm is passed to contourf, either or both of the
vmin, vmax attributes of that norm are now respected.
Formerly they were respected only if both were
View
26 lib/matplotlib/patches.py
@@ -767,12 +767,8 @@ def __init__(self, xy, closed=True, **kwargs):
"""
Patch.__init__(self, **kwargs)
- xy = np.asarray(xy, np.float_)
- self._path = Path(xy)
self._closed = closed
- if closed and len(xy):
- xy = np.concatenate([xy, [xy[0]]])
- self._set_xy(xy)
+ self.set_xy(xy)
def get_path(self):
return self._path
@@ -783,20 +779,22 @@ def get_closed(self):
def set_closed(self, closed):
if self._closed == bool(closed):
return
- self._closed = closed
- xy = self._get_xy()
- if closed:
+ self._closed = bool(closed)
+ self.set_xy(self.get_xy())
+
+ def get_xy(self):
+ return self._path.vertices
+
+ def set_xy(self, xy):
+ xy = np.asarray(xy, np.float_)
+ if self._closed:
if len(xy) and (xy[0] != xy[-1]).any():
xy = np.concatenate([xy, [xy[0]]])
else:
if len(xy)>2 and (xy[0]==xy[-1]).all():
- xy = xy[0:-1]
- self._set_xy(xy)
+ xy = xy[:-1]
+ self._path = Path(xy, closed=self._closed)
- def get_xy(self):
- return self._path.vertices
- def set_xy(self, vertices):
- self._path = Path(vertices, closed=self._closed)
_get_xy = get_xy
_set_xy = set_xy
xy = property(
View
16 lib/matplotlib/tests/test_patches.py
@@ -0,0 +1,16 @@
+from numpy.testing import assert_array_equal
+from matplotlib.patches import Polygon
+
+def test_Polygon_close():
+ #1018
+ xy = [[0,0], [0,1], [1,1]]
+ xyclosed = xy + [[0,0]]
+ p = Polygon(xy, closed=True)
+ assert_array_equal(p.get_xy(), xyclosed)
+ p.set_xy(xy)
+ assert_array_equal(p.get_xy(), xyclosed)
+ p = Polygon(xy, closed=False)
+ assert_array_equal(p.get_xy(), xy)
+ p.set_xy(xyclosed)
+ assert_array_equal(p.get_xy(), xy)
+
Please sign in to comment.
Something went wrong with that request. Please try again.