-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
ScalarMappable should copy its input and allow non-arrays #18841
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
Comments
I'd love to take this up! :)
|
To solve this, I added |
Problem
Recently I wanted to draw some colormapped vlines. As LineCollection inherits from ScalarMappable, one can indeed write e.g.
and get

Unfortunately,
array
kwarg only accepts ndarrays, and not e.g. nested lists:plt.vlines(np.arange(10), 0, 1, array=[*range(10)])
crashes (at draw time, which is even worse) with "AttributeError: 'list' object has no attribute 'ndim'". This is unlike most other Axes/pyplot APIs (e.g.imshow
), which happily accept lists (nested/2D lists, for imshow).array
kwarg is not copied, so later changes to it get reflected back into the artist (i.e. doingvals[5] = 45
after the call tovlines
still affects the line colors). Again, this is unlike other Axes/pyplot APIs (e.g.imshow
), which insulate the artist from later changes to the input.Proposed Solution
Make a copy of the input and cast it to arrays. (Well, modulo unit handling...)
Additional context and prior art
Behave like
imshow
.The text was updated successfully, but these errors were encountered: