Title: ScalarMappable should copy its input and allow non-arrays · Issue #18841 · matplotlib/matplotlib · GitHub
Open Graph Title: ScalarMappable should copy its input and allow non-arrays · Issue #18841 · matplotlib/matplotlib
X Title: ScalarMappable should copy its input and allow non-arrays · Issue #18841 · matplotlib/matplotlib
Description: Problem Recently I wanted to draw some colormapped vlines. As LineCollection inherits from ScalarMappable, one can indeed write e.g. from pylab import * xs = vals = np.arange(10) plt.vlines(xs, 0, 1, array=vals) plt.show() and get Unfort...
Open Graph Description: Problem Recently I wanted to draw some colormapped vlines. As LineCollection inherits from ScalarMappable, one can indeed write e.g. from pylab import * xs = vals = np.arange(10) plt.vlines(xs, 0, ...
X Description: Problem Recently I wanted to draw some colormapped vlines. As LineCollection inherits from ScalarMappable, one can indeed write e.g. from pylab import * xs = vals = np.arange(10) plt.vlines(xs, 0, ...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/18841
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"ScalarMappable should copy its input and allow non-arrays","articleBody":"\u003c!--\r\nWelcome! Thanks for thinking of a way to improve Matplotlib.\r\n\r\n\r\nBefore creating a new feature request please search the issues for relevant feature requests.\r\n--\u003e\r\n\r\n### Problem\r\n\r\nRecently I wanted to draw some colormapped vlines. As LineCollection inherits from ScalarMappable, one can indeed write e.g.\r\n```python\r\nfrom pylab import *\r\nxs = vals = np.arange(10)\r\nplt.vlines(xs, 0, 1, array=vals)\r\nplt.show()\r\n```\r\nand get\r\n\r\n\r\nUnfortunately,\r\n1) The `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).\r\n2) The `array` kwarg is not copied, so later changes to it get reflected back into the artist (i.e. doing `vals[5] = 45` *after* the call to `vlines` 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.\r\n\r\n### Proposed Solution\r\n\r\nMake a copy of the input and cast it to arrays. (Well, modulo unit handling...)\r\n\r\n### Additional context and prior art\r\n\r\nBehave like `imshow`.","author":{"url":"https://github.com/anntzer","@type":"Person","name":"anntzer"},"datePublished":"2020-10-29T20:44:12.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/18841/matplotlib/issues/18841"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:d18dad52-cf5e-a6a0-40ee-5a903112bede |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 96DC:16BA45:806653:B7A243:6A51045C |
| html-safe-nonce | 692ddda4a983aebe46fed840d30f4669dd12bc0fd863bd0a857c148f0b35ebd7 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NkRDOjE2QkE0NTo4MDY2NTM6QjdBMjQzOjZBNTEwNDVDIiwidmlzaXRvcl9pZCI6Ijc1NjY1OTU5OTM0MTM2ODIyNjgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | f151e7af0f557d1f3faa1cbaff33e8dba1762ba4ab702e8b28e9a7902c84a84d |
| hovercard-subject-tag | issue:732646421 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/matplotlib/matplotlib/18841/issue_layout |
| twitter:image | https://opengraph.githubassets.com/81bdfa54aad37324668f6698c42faa50cd7ff8fc036c78ab9ad6e4b62c46fc4b/matplotlib/matplotlib/issues/18841 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/81bdfa54aad37324668f6698c42faa50cd7ff8fc036c78ab9ad6e4b62c46fc4b/matplotlib/matplotlib/issues/18841 |
| og:image:alt | Problem Recently I wanted to draw some colormapped vlines. As LineCollection inherits from ScalarMappable, one can indeed write e.g. from pylab import * xs = vals = np.arange(10) plt.vlines(xs, 0, ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | anntzer |
| hostname | github.com |
| expected-hostname | github.com |
| None | 38906a4da4e3e9fd88dfeacee232f5932c0c5f7495de3b4efc53ddfac7173d12 |
| turbo-cache-control | no-preview |
| go-import | github.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git |
| octolytics-dimension-user_id | 215947 |
| octolytics-dimension-user_login | matplotlib |
| octolytics-dimension-repository_id | 1385122 |
| octolytics-dimension-repository_nwo | matplotlib/matplotlib |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1385122 |
| octolytics-dimension-repository_network_root_nwo | matplotlib/matplotlib |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 90441ea9b98e7491aa6ebcd135fccce4e2396f48 |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width