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

Skip to content

Commit cfcc6a0

Browse files
committed
Add tests
1 parent 0abe367 commit cfcc6a0

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

lib/matplotlib/collections.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,7 +1091,6 @@ def set_verts(self, verts, closed=True):
10911091
connection at the end.
10921092
"""
10931093
self.stale = True
1094-
# This is much faster than having Path do it one at a time.
10951094
if isinstance(verts, np.ma.MaskedArray):
10961095
verts = verts.astype(float).filled(np.nan)
10971096

@@ -1102,7 +1101,9 @@ def set_verts(self, verts, closed=True):
11021101

11031102
# Fast path for arrays
11041103
if isinstance(verts, np.ndarray):
1105-
verts_pad = np.concatenate((verts, verts[:, -1:]), axis=1)
1104+
verts_pad = np.concatenate((verts, verts[:, 0:1]), axis=1)
1105+
# Creating the codes once is much faster than having Path do it
1106+
# separately each time by passing closed=True.
11061107
codes = np.empty(verts_pad.shape[1], dtype=mpath.Path.code_type)
11071108
codes[:] = mpath.Path.LINETO
11081109
codes[0] = mpath.Path.MOVETO
@@ -1118,11 +1119,7 @@ def set_verts(self, verts, closed=True):
11181119
else:
11191120
xy = np.asarray(xy)
11201121
xy = np.concatenate([xy, xy[0:1]])
1121-
codes = np.empty(xy.shape[0], dtype=mpath.Path.code_type)
1122-
codes[:] = mpath.Path.LINETO
1123-
codes[0] = mpath.Path.MOVETO
1124-
codes[-1] = mpath.Path.CLOSEPOLY
1125-
self._paths.append(mpath.Path(xy, codes))
1122+
self._paths.append(mpath.Path(xy, closed=True))
11261123
else:
11271124
self._paths.append(mpath.Path(xy))
11281125

lib/matplotlib/tests/test_collections.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
import matplotlib.pyplot as plt
1313
import matplotlib.collections as mcollections
1414
import matplotlib.transforms as mtransforms
15-
from matplotlib.collections import Collection, LineCollection, EventCollection
15+
from matplotlib.collections import (Collection, LineCollection,
16+
EventCollection, PolyCollection)
1617
from matplotlib.testing.decorators import image_comparison
1718

1819

@@ -612,3 +613,13 @@ def test_EventCollection_nosort():
612613
arr = np.array([3, 2, 1, 10])
613614
coll = EventCollection(arr)
614615
np.testing.assert_array_equal(arr, np.array([3, 2, 1, 10]))
616+
617+
618+
def test_collection_set_verts_array():
619+
verts = np.arange(80, dtype=np.double).reshape(10, 4, 2)
620+
col_arr = PolyCollection(verts)
621+
col_list = PolyCollection(list(verts))
622+
assert len(col_arr._paths) == len(col_list._paths)
623+
for ap, lp in zip(col_arr._paths, col_list._paths):
624+
assert np.array_equal(ap._vertices, lp._vertices)
625+
assert np.array_equal(ap._codes, lp._codes)

0 commit comments

Comments
 (0)