Title: [Bug]: regression with ScalarMappable and `.set_array` and `autoscale_None` · Issue #20902 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: regression with ScalarMappable and `.set_array` and `autoscale_None` · Issue #20902 · matplotlib/matplotlib
X Title: [Bug]: regression with ScalarMappable and `.set_array` and `autoscale_None` · Issue #20902 · matplotlib/matplotlib
Description: Bug summary We are creating manual ScalarMappable instances in some cases where colorbar creation is detached from the plotting event. Changed in #20511 an element-wise comparison of the color array is made, however, with ScalarMappable....
Open Graph Description: Bug summary We are creating manual ScalarMappable instances in some cases where colorbar creation is detached from the plotting event. Changed in #20511 an element-wise comparison of the color arra...
X Description: Bug summary We are creating manual ScalarMappable instances in some cases where colorbar creation is detached from the plotting event. Changed in #20511 an element-wise comparison of the color arra...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/20902
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: regression with ScalarMappable and `.set_array` and `autoscale_None`","articleBody":"### Bug summary\r\n\r\nWe are creating manual `ScalarMappable` instances in some cases where colorbar creation is detached from the plotting event. Changed in #20511 an element-wise comparison of the color array is made, however, with `ScalarMappable.set_array` there appears to be no assurances that the `._A` attribute will support such comparison.\r\n\r\n### Code for reproduction\r\n\r\n```python\r\nimport matplotlib as mpl\r\nimport matplotlib.pyplot as plt\r\nnorm = mpl.colors.LogNorm()\r\ncmap = mpl.cm.get_cmap(\"viridis\")\r\nfig, ax = plt.subplots()\r\npts = mpl.cm.ScalarMappable(norm=norm, cmap=cmap)\r\npts.set_array([0.1, 0.9])\r\nplt.colorbar(pts)\r\n```\r\n\r\n\r\n### Actual outcome\r\n\r\n```\r\n---------------------------------------------------------------------------\r\nTypeError Traceback (most recent call last)\r\n\u003cipython-input-1-adec5b1bbfd1\u003e in \u003cmodule\u003e\r\n 6 pts = mpl.cm.ScalarMappable(norm=norm, cmap=cmap)\r\n 7 pts.set_array([0.1, 0.9])\r\n----\u003e 8 plt.colorbar(pts)\r\n\r\n~/rms-python/envs/mpl34/lib/python3.7/site-packages/matplotlib/pyplot.py in colorbar(mappable, cax, ax, **kw)\r\n 2354 'an image (with imshow) or a contour set ('\r\n 2355 'with contourf).')\r\n-\u003e 2356 ret = gcf().colorbar(mappable, cax=cax, ax=ax, **kw)\r\n 2357 return ret\r\n 2358\r\n\r\n~/rms-python/envs/mpl34/lib/python3.7/site-packages/matplotlib/figure.py in colorbar(self, mappable, cax, ax, use_gridspec, **kw)\r\n 1174 'panchor']\r\n 1175 cb_kw = {k: v for k, v in kw.items() if k not in NON_COLORBAR_KEYS}\r\n-\u003e 1176 cb = cbar.Colorbar(cax, mappable, **cb_kw)\r\n 1177\r\n 1178 self.sca(current_ax)\r\n\r\n~/rms-python/envs/mpl34/lib/python3.7/site-packages/matplotlib/colorbar.py in __init__(self, ax, mappable, **kwargs)\r\n 1170 # even if mappable.draw has not yet been called.\r\n 1171 if mappable.get_array() is not None:\r\n-\u003e 1172 mappable.autoscale_None()\r\n 1173\r\n 1174 self.mappable = mappable\r\n\r\n~/rms-python/envs/mpl34/lib/python3.7/site-packages/matplotlib/cm.py in autoscale_None(self)\r\n 474 if self._A is None:\r\n 475 raise TypeError('You must first set_array for mappable')\r\n--\u003e 476 self.norm.autoscale_None(self._A)\r\n 477 self.changed()\r\n 478\r\n\r\n~/rms-python/envs/mpl34/lib/python3.7/site-packages/matplotlib/colors.py in autoscale_None(self, A)\r\n 1541 def autoscale_None(self, A):\r\n 1542 # docstring inherited.\r\n-\u003e 1543 super().autoscale_None(np.ma.array(A, mask=(A \u003c= 0)))\r\n 1544\r\n 1545\r\n\r\nTypeError: '\u003c=' not supported between instances of 'list' and 'int'\r\n```\r\n\r\n### Expected outcome\r\n\r\nNo error.\r\n\r\n### Operating system\r\n\r\nUbuntu\r\n\r\n### Matplotlib Version\r\n\r\n3.4.3\r\n\r\n### Matplotlib Backend\r\n\r\nagg\r\n\r\n### Python version\r\n\r\n3.7.10\r\n\r\n### Jupyter version\r\n\r\nNA\r\n\r\n### Other libraries\r\n\r\nnumpy 1.18.5\r\n\r\n### Installation\r\n\r\nconda\r\n\r\n### Conda channel\r\n\r\nconda-forge","author":{"url":"https://github.com/ryandvmartin","@type":"Person","name":"ryandvmartin"},"datePublished":"2021-08-25T18:53:21.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":4},"url":"https://github.com/20902/matplotlib/issues/20902"}
| 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:e400744a-2806-e6bb-8663-8ec30bacc848 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DF36:16FBA0:67FC1:8EC51:6A512207 |
| html-safe-nonce | 9ef8f1112a7544d293608df3aba6f106741d3acb03f0597e0584ea973e0ed78a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERjM2OjE2RkJBMDo2N0ZDMTo4RUM1MTo2QTUxMjIwNyIsInZpc2l0b3JfaWQiOiIxNDY4NzUxNzUwNDA4MjQ5ODYzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 47544fe1bbfdab0539346e36fb023ede37d36cf99a3f5500e27be012b44a6a08 |
| hovercard-subject-tag | issue:979527196 |
| 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/20902/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e43fb62c48babfc1b720233fb9c05acd793d50e2877d748f0a4c7abdfdd5d9ab/matplotlib/matplotlib/issues/20902 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e43fb62c48babfc1b720233fb9c05acd793d50e2877d748f0a4c7abdfdd5d9ab/matplotlib/matplotlib/issues/20902 |
| og:image:alt | Bug summary We are creating manual ScalarMappable instances in some cases where colorbar creation is detached from the plotting event. Changed in #20511 an element-wise comparison of the color arra... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ryandvmartin |
| hostname | github.com |
| expected-hostname | github.com |
| None | 689b683944b0d7f015d0e776452c970832fa81b82dc15284469b556ecced715b |
| 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 | 942b51ed3bd5feee3d5e2719f890a5fe286edbbb |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width