Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c6cc861

Browse filesBrowse files
committed
patches.polygon: fix bug in handling of path closing, #1018.
This is a modification of that pull request, with a test added.
1 parent 447a7cc commit c6cc861
Copy full SHA for c6cc861

File tree

Expand file treeCollapse file tree

3 files changed

+33
-14
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+33
-14
lines changed

‎CHANGELOG

Copy file name to clipboardExpand all lines: CHANGELOG
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2012-08-11 Fix path-closing bug in patches.Polygon, so that regardless
2+
of whether the path is the initial one or was subsequently
3+
set by set_xy(), get_xy() will return a closed path if and
4+
only if get_closed() is True. Thanks to Jacob Vanderplas. - EF
5+
16
2012-08-05 When a norm is passed to contourf, either or both of the
27
vmin, vmax attributes of that norm are now respected.
38
Formerly they were respected only if both were

‎lib/matplotlib/patches.py

Copy file name to clipboardExpand all lines: lib/matplotlib/patches.py
+12-14Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -767,12 +767,8 @@ def __init__(self, xy, closed=True, **kwargs):
767767
768768
"""
769769
Patch.__init__(self, **kwargs)
770-
xy = np.asarray(xy, np.float_)
771-
self._path = Path(xy)
772770
self._closed = closed
773-
if closed and len(xy):
774-
xy = np.concatenate([xy, [xy[0]]])
775-
self._set_xy(xy)
771+
self.set_xy(xy)
776772

777773
def get_path(self):
778774
return self._path
@@ -783,20 +779,22 @@ def get_closed(self):
783779
def set_closed(self, closed):
784780
if self._closed == bool(closed):
785781
return
786-
self._closed = closed
787-
xy = self._get_xy()
788-
if closed:
782+
self._closed = bool(closed)
783+
self.set_xy(self.get_xy())
784+
785+
def get_xy(self):
786+
return self._path.vertices
787+
788+
def set_xy(self, xy):
789+
xy = np.asarray(xy, np.float_)
790+
if self._closed:
789791
if len(xy) and (xy[0] != xy[-1]).any():
790792
xy = np.concatenate([xy, [xy[0]]])
791793
else:
792794
if len(xy)>2 and (xy[0]==xy[-1]).all():
793-
xy = xy[0:-1]
794-
self._set_xy(xy)
795+
xy = xy[:-1]
796+
self._path = Path(xy, closed=self._closed)
795797

796-
def get_xy(self):
797-
return self._path.vertices
798-
def set_xy(self, vertices):
799-
self._path = Path(vertices, closed=self._closed)
800798
_get_xy = get_xy
801799
_set_xy = set_xy
802800
xy = property(

‎lib/matplotlib/tests/test_patches.py

Copy file name to clipboard
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from numpy.testing import assert_array_equal
2+
from matplotlib.patches import Polygon
3+
4+
def test_Polygon_close():
5+
#1018
6+
xy = [[0,0], [0,1], [1,1]]
7+
xyclosed = xy + [[0,0]]
8+
p = Polygon(xy, closed=True)
9+
assert_array_equal(p.get_xy(), xyclosed)
10+
p.set_xy(xy)
11+
assert_array_equal(p.get_xy(), xyclosed)
12+
p = Polygon(xy, closed=False)
13+
assert_array_equal(p.get_xy(), xy)
14+
p.set_xy(xyclosed)
15+
assert_array_equal(p.get_xy(), xy)
16+

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.