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

Skip to content

Commit abdd1cc

Browse files
committed
Merge pull request matplotlib#3239 from mdboom/polycollection-closed
Fix auto-closing in PolyCollection
2 parents 9e0dd74 + 7ef5299 commit abdd1cc

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

lib/matplotlib/collections.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -809,10 +809,10 @@ def set_verts(self, verts, closed=True):
809809
for xy in verts:
810810
if len(xy):
811811
if np.ma.isMaskedArray(xy):
812-
xy = np.ma.concatenate([xy, np.zeros((1, 2))])
812+
xy = np.ma.concatenate([xy, xy[0:1]])
813813
else:
814814
xy = np.asarray(xy)
815-
xy = np.concatenate([xy, np.zeros((1, 2))])
815+
xy = np.concatenate([xy, xy[0:1]])
816816
codes = np.empty(xy.shape[0], dtype=mpath.Path.code_type)
817817
codes[:] = mpath.Path.LINETO
818818
codes[0] = mpath.Path.MOVETO

lib/matplotlib/tests/test_collections.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,44 @@ def test_EllipseCollection():
475475
ax.autoscale_view()
476476

477477

478+
@image_comparison(baseline_images=['polycollection_close'],
479+
extensions=['png'], remove_text=True)
480+
def test_polycollection_close():
481+
from mpl_toolkits.mplot3d import Axes3D
482+
483+
vertsQuad = [
484+
[[0., 0.], [0., 1.], [1., 1.], [1., 0.]],
485+
[[0., 1.], [2., 3.], [2., 2.], [1., 1.]],
486+
[[2., 2.], [2., 3.], [4., 1.], [3., 1.]],
487+
[[3., 0.], [3., 1.], [4., 1.], [4., 0.]]]
488+
489+
fig = plt.figure()
490+
ax = Axes3D(fig)
491+
492+
colors = ['r', 'g', 'b', 'y', 'k']
493+
zpos = list(range(5))
494+
495+
poly = mcollections.PolyCollection(
496+
vertsQuad * len(zpos), linewidth=0.25)
497+
poly.set_alpha(0.7)
498+
499+
## need to have a z-value for *each* polygon = element!
500+
zs = []
501+
cs = []
502+
for z, c in zip(zpos, colors):
503+
zs.extend([z] * len(vertsQuad))
504+
cs.extend([c] * len(vertsQuad))
505+
506+
poly.set_color(cs)
507+
508+
ax.add_collection3d(poly, zs=zs, zdir='y')
509+
510+
## axis limit settings:
511+
ax.set_xlim3d(0, 4)
512+
ax.set_zlim3d(0, 3)
513+
ax.set_ylim3d(0, 4)
514+
515+
478516
if __name__ == '__main__':
479517
import nose
480518
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

0 commit comments

Comments
 (0)