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

Skip to content

Fix PolyCollection.set_verts optimization. #18030

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/matplotlib/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -1109,7 +1109,7 @@ def __init__(self, verts, sizes=None, closed=True, **kwargs):
verts : list of array-like
The sequence of polygons [*verts0*, *verts1*, ...] where each
element *verts_i* defines the vertices of polygon *i* as a 2D
array-like of of shape (M, 2).
array-like of shape (M, 2).
sizes : array-like, default: None
Squared scaling factors for the polygons. The coordinates of each
polygon *verts_i* are multiplied by the square-root of the
Expand All @@ -1136,7 +1136,7 @@ def set_verts(self, verts, closed=True):
verts : list of array-like
The sequence of polygons [*verts0*, *verts1*, ...] where each
element *verts_i* defines the vertices of polygon *i* as a 2D
array-like of of shape (M, 2).
array-like of shape (M, 2).
closed : bool, default: True
Whether the polygon should be closed by adding a CLOSEPOLY
connection at the end.
Expand All @@ -1151,7 +1151,7 @@ def set_verts(self, verts, closed=True):
return

# Fast path for arrays
if isinstance(verts, np.ndarray):
if isinstance(verts, np.ndarray) and len(verts.shape) == 3:
verts_pad = np.concatenate((verts, verts[:, :1]), axis=1)
# Creating the codes once is much faster than having Path do it
# separately each time by passing closed=True.
Expand Down
8 changes: 8 additions & 0 deletions lib/matplotlib/tests/test_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,14 @@ def test_collection_set_verts_array():
assert np.array_equal(ap._vertices, lp._vertices)
assert np.array_equal(ap._codes, lp._codes)

verts_tuple = np.empty(10, dtype=object)
verts_tuple[:] = [tuple(tuple(y) for y in x) for x in verts]
col_arr_tuple = PolyCollection(verts_tuple)
assert len(col_arr._paths) == len(col_arr_tuple._paths)
for ap, atp in zip(col_arr._paths, col_arr_tuple._paths):
assert np.array_equal(ap._vertices, atp._vertices)
assert np.array_equal(ap._codes, atp._codes)


def test_blended_collection_autolim():
a = [1, 2, 4]
Expand Down