diff --git a/lib/matplotlib/collections.py b/lib/matplotlib/collections.py index b573d3bb9e21..7a4330250e0d 100644 --- a/lib/matplotlib/collections.py +++ b/lib/matplotlib/collections.py @@ -809,10 +809,10 @@ def set_verts(self, verts, closed=True): for xy in verts: if len(xy): if np.ma.isMaskedArray(xy): - xy = np.ma.concatenate([xy, np.zeros((1, 2))]) + xy = np.ma.concatenate([xy, xy[0:1]]) else: xy = np.asarray(xy) - xy = np.concatenate([xy, np.zeros((1, 2))]) + xy = np.concatenate([xy, xy[0:1]]) codes = np.empty(xy.shape[0], dtype=mpath.Path.code_type) codes[:] = mpath.Path.LINETO codes[0] = mpath.Path.MOVETO diff --git a/lib/matplotlib/tests/baseline_images/test_collections/polycollection_close.png b/lib/matplotlib/tests/baseline_images/test_collections/polycollection_close.png new file mode 100644 index 000000000000..d8b85287986a Binary files /dev/null and b/lib/matplotlib/tests/baseline_images/test_collections/polycollection_close.png differ diff --git a/lib/matplotlib/tests/test_collections.py b/lib/matplotlib/tests/test_collections.py index a91d20ca83ec..886dc791c9a9 100644 --- a/lib/matplotlib/tests/test_collections.py +++ b/lib/matplotlib/tests/test_collections.py @@ -475,6 +475,44 @@ def test_EllipseCollection(): ax.autoscale_view() +@image_comparison(baseline_images=['polycollection_close'], + extensions=['png'], remove_text=True) +def test_polycollection_close(): + from mpl_toolkits.mplot3d import Axes3D + + vertsQuad = [ + [[0., 0.], [0., 1.], [1., 1.], [1., 0.]], + [[0., 1.], [2., 3.], [2., 2.], [1., 1.]], + [[2., 2.], [2., 3.], [4., 1.], [3., 1.]], + [[3., 0.], [3., 1.], [4., 1.], [4., 0.]]] + + fig = plt.figure() + ax = Axes3D(fig) + + colors = ['r', 'g', 'b', 'y', 'k'] + zpos = list(range(5)) + + poly = mcollections.PolyCollection( + vertsQuad * len(zpos), linewidth=0.25) + poly.set_alpha(0.7) + + ## need to have a z-value for *each* polygon = element! + zs = [] + cs = [] + for z, c in zip(zpos, colors): + zs.extend([z] * len(vertsQuad)) + cs.extend([c] * len(vertsQuad)) + + poly.set_color(cs) + + ax.add_collection3d(poly, zs=zs, zdir='y') + + ## axis limit settings: + ax.set_xlim3d(0, 4) + ax.set_zlim3d(0, 3) + ax.set_ylim3d(0, 4) + + if __name__ == '__main__': import nose nose.runmodule(argv=['-s', '--with-doctest'], exit=False)