Closed
Description
Bug report
This optimisation fails if verts
is an ndarray containing lists of varying sizes (e.g. regions with different numbers of points)
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.collections import PolyCollection
# Vertices: irregular shapes
regions = (
((1, 1), (1, 2), (2, 2)),
((3, 3), (3, 4), (4, 4), (6, 4)),
)
# Use numpy to select vertices (in real life not through a static list)
selection = np.array([1, 0, 1])
regions = np.array(regions, dtype=object)
regions = regions[selection]
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.set_xlim(0, 10)
ax.set_ylim(0, 10)
c = PolyCollection(regions)
ax.add_collection(c)
plt.show()
Actual outcome
Traceback (most recent call last):
File "./ff", line 24, in <module>
c = PolyCollection(regions)
File "/home/michael/dev/pints/venv/lib/python3.8/site-packages/matplotlib/collections.py", line 1125, in __init__
self.set_verts(verts, closed)
File "/home/michael/dev/pints/venv/lib/python3.8/site-packages/matplotlib/collections.py", line 1153, in set_verts
verts_pad = np.concatenate((verts, verts[:, :1]), axis=1)
IndexError: too many indices for array: array is 1-dimensional, but 2 were indexed
Expected outcome
Works as normal
Matplotlib version
Python3.8 and matplotlib 3.3.0
Workaround is to just do a .tolist() before passing regions to matplotlib. But the line that checks if its an array should probably check if it's a rectangular array
Metadata
Metadata
Assignees
Labels
No labels