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

Skip to content

Commit 676f82a

Browse files
committed
Fix polygon closing and provide option not to close (used by hist(histtype="step"))
svn path=/trunk/matplotlib/; revision=5410
1 parent eb4c833 commit 676f82a

3 files changed

Lines changed: 20 additions & 7 deletions

File tree

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2008-06-06 Fix closed polygon patch and also provide the option to
2+
not close the polygon - MGD
3+
14
2008-06-05 Fix some dpi-changing-related problems with PolyCollection,
25
as called by Axes.scatter() - MGD
36

lib/matplotlib/axes.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -345,12 +345,16 @@ def makefill(x, y):
345345
seg = mpatches.Polygon(zip(x, y),
346346
facecolor = facecolor,
347347
fill=True,
348+
closed=closed
348349
)
349350
self.set_patchprops(seg, **kwargs)
350351
ret.append(seg)
351352

352-
if self.command == 'plot': func = makeline
353-
else: func = makefill
353+
if self.command == 'plot':
354+
func = makeline
355+
else:
356+
closed = kwargs.pop("closed")
357+
func = makefill
354358
if multicol:
355359
for j in range(y.shape[1]):
356360
func(x[:,j], y[:,j])
@@ -387,12 +391,16 @@ def makefill(x, y):
387391
seg = mpatches.Polygon(zip(x, y),
388392
facecolor = facecolor,
389393
fill=True,
394+
closed=closed
390395
)
391396
self.set_patchprops(seg, **kwargs)
392397
ret.append(seg)
393398

394-
if self.command == 'plot': func = makeline
395-
else: func = makefill
399+
if self.command == 'plot':
400+
func = makeline
401+
else:
402+
closed = kwargs.pop('closed')
403+
func = makefill
396404

397405
if multicol:
398406
for j in range(y.shape[1]):
@@ -4934,6 +4942,8 @@ def fill(self, *args, **kwargs):
49344942
49354943
See examples/fill_between.py for more examples.
49364944
4945+
The closed kwarg will close the polygon when True (default).
4946+
49374947
kwargs control the Polygon properties:
49384948
%(Polygon)s
49394949
"""
@@ -5809,7 +5819,7 @@ def hist(self, x, bins=10, normed=False, cumulative=False,
58095819
x,y = y,x
58105820
elif orientation != 'vertical':
58115821
raise ValueError, 'invalid orientation: %s' % orientation
5812-
patches.append( self.fill(x,y) )
5822+
patches.append( self.fill(x,y,closed=False) )
58135823

58145824
# adopted from adjust_x/ylim part of the bar method
58155825
if orientation == 'horizontal':

lib/matplotlib/patches.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ class Polygon(Patch):
531531
def __str__(self):
532532
return "Poly((%g, %g) ...)" % tuple(self._path.vertices[0])
533533

534-
def __init__(self, xy, **kwargs):
534+
def __init__(self, xy, closed=True, **kwargs):
535535
"""
536536
xy is a numpy array with shape Nx2
537537
@@ -541,7 +541,7 @@ def __init__(self, xy, **kwargs):
541541
"""
542542
Patch.__init__(self, **kwargs)
543543
xy = np.asarray(xy, np.float_)
544-
if len(xy) and xy[0] != xy[-1]:
544+
if closed and len(xy) and (xy[0] != xy[-1]).any():
545545
xy = np.concatenate([xy, [xy[0]]])
546546
self._path = Path(xy)
547547
__init__.__doc__ = cbook.dedent(__init__.__doc__) % artist.kwdocd

0 commit comments

Comments
 (0)