Title: [ENH]: Ability to set imshow vmin/vmax with units · Issue #25062 · matplotlib/matplotlib · GitHub
Open Graph Title: [ENH]: Ability to set imshow vmin/vmax with units · Issue #25062 · matplotlib/matplotlib
X Title: [ENH]: Ability to set imshow vmin/vmax with units · Issue #25062 · matplotlib/matplotlib
Description: Problem Trying to use imshow with unit-ful data and setting vmin/vmax with units fails. It would be great if this was possible! import matplotlib.pyplot as plt import numpy as np import pint ureg = pint.UnitRegistry() ureg.setup_matplotl...
Open Graph Description: Problem Trying to use imshow with unit-ful data and setting vmin/vmax with units fails. It would be great if this was possible! import matplotlib.pyplot as plt import numpy as np import pint ureg =...
X Description: Problem Trying to use imshow with unit-ful data and setting vmin/vmax with units fails. It would be great if this was possible! import matplotlib.pyplot as plt import numpy as np import pint ureg =...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/25062
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[ENH]: Ability to set imshow vmin/vmax with units ","articleBody":"### Problem\n\nTrying to use `imshow` with unit-ful data and setting vmin/vmax with units fails. It would be great if this was possible!\r\n\r\n\r\n```python\r\nimport matplotlib.pyplot as plt\r\nimport numpy as np\r\n\r\nimport pint\r\nureg = pint.UnitRegistry()\r\nureg.setup_matplotlib()\r\n\r\nX, Y = np.meshgrid(np.linspace(-3, 3, 16), np.linspace(-3, 3, 16))\r\nZ = (1 - X/2 + X**5 + Y**3) * np.exp(-X**2 - Y**2)\r\nZ *= ureg.kg\r\n\r\nfig, ax = plt.subplots()\r\nax.imshow(Z, vmin=1*ureg.kg, vmax=2*ureg.kg)\r\nplt.show()\r\n```\r\n\r\n```python\r\n% python test.py\r\n/Users/dstansby/github/matplotlib/lib/matplotlib/cbook.py:672: UnitStrippedWarning: The unit of the quantity is stripped when downcasting to ndarray.\r\n x = np.array(x, subok=True, copy=copy)\r\n/Users/dstansby/github/matplotlib/lib/matplotlib/image.py:452: UnitStrippedWarning: The unit of the quantity is stripped when downcasting to ndarray.\r\n dv = np.float64(self.norm.vmax) - np.float64(self.norm.vmin)\r\n/Users/dstansby/github/matplotlib/lib/matplotlib/image.py:453: UnitStrippedWarning: The unit of the quantity is stripped when downcasting to ndarray.\r\n vmid = np.float64(self.norm.vmin) + dv / 2\r\n/Users/dstansby/github/matplotlib/lib/matplotlib/image.py:482: UnitStrippedWarning: The unit of the quantity is stripped when downcasting to ndarray.\r\n vrange = np.array([vmin, vmax], dtype=scaled_dtype)\r\nTraceback (most recent call last):\r\n File \"/Users/dstansby/mambaforge/envs/mpl/lib/python3.10/site-packages/pint/facets/plain/quantity.py\", line 707, in __float__\r\n raise DimensionalityError(self._units, \"dimensionless\")\r\npint.errors.DimensionalityError: Cannot convert from 'kilogram' to 'dimensionless'\r\n\r\nThe above exception was the direct cause of the following exception:\r\n\r\nTraceback (most recent call last):\r\n File \"/Users/dstansby/github/matplotlib/lib/matplotlib/backend_bases.py\", line 1223, in _on_timer\r\n ret = func(*args, **kwargs)\r\n File \"/Users/dstansby/github/matplotlib/lib/matplotlib/backends/backend_macosx.py\", line 68, in callback_func\r\n callback()\r\n File \"/Users/dstansby/github/matplotlib/lib/matplotlib/backends/backend_macosx.py\", line 88, in _draw_idle\r\n self.draw()\r\n File \"/Users/dstansby/github/matplotlib/lib/matplotlib/backends/backend_macosx.py\", line 50, in draw\r\n super().draw()\r\n File \"/Users/dstansby/github/matplotlib/lib/matplotlib/backends/backend_agg.py\", line 400, in draw\r\n self.figure.draw(self.renderer)\r\n File \"/Users/dstansby/github/matplotlib/lib/matplotlib/artist.py\", line 95, in draw_wrapper\r\n result = draw(artist, renderer, *args, **kwargs)\r\n File \"/Users/dstansby/github/matplotlib/lib/matplotlib/artist.py\", line 72, in draw_wrapper\r\n return draw(artist, renderer)\r\n File \"/Users/dstansby/github/matplotlib/lib/matplotlib/figure.py\", line 3116, in draw\r\n mimage._draw_list_compositing_images(\r\n File \"/Users/dstansby/github/matplotlib/lib/matplotlib/image.py\", line 131, in _draw_list_compositing_images\r\n a.draw(renderer)\r\n File \"/Users/dstansby/github/matplotlib/lib/matplotlib/artist.py\", line 72, in draw_wrapper\r\n return draw(artist, renderer)\r\n File \"/Users/dstansby/github/matplotlib/lib/matplotlib/axes/_base.py\", line 3066, in draw\r\n mimage._draw_list_compositing_images(\r\n File \"/Users/dstansby/github/matplotlib/lib/matplotlib/image.py\", line 131, in _draw_list_compositing_images\r\n a.draw(renderer)\r\n File \"/Users/dstansby/github/matplotlib/lib/matplotlib/artist.py\", line 72, in draw_wrapper\r\n return draw(artist, renderer)\r\n File \"/Users/dstansby/github/matplotlib/lib/matplotlib/image.py\", line 641, in draw\r\n im, l, b, trans = self.make_image(\r\n File \"/Users/dstansby/github/matplotlib/lib/matplotlib/image.py\", line 948, in make_image\r\n return self._make_image(self._A, bbox, transformed_bbox, clip,\r\n File \"/Users/dstansby/github/matplotlib/lib/matplotlib/image.py\", line 482, in _make_image\r\n vrange = np.array([vmin, vmax], dtype=scaled_dtype)\r\nValueError: setting an array element with a sequence.\r\n```\n\n### Proposed solution\n\n_No response_","author":{"url":"https://github.com/dstansby","@type":"Person","name":"dstansby"},"datePublished":"2023-01-23T16:19:13.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/25062/matplotlib/issues/25062"}
| 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:5745d5f0-3993-ff36-06a8-5961d6df501e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C264:2B78D3:96F537:C89920:6A5315CC |
| html-safe-nonce | 400e4fd644c7717a93e37bd560d418748b1ff372d6f149db6eb5ef1104ed489b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMjY0OjJCNzhEMzo5NkY1Mzc6Qzg5OTIwOjZBNTMxNUNDIiwidmlzaXRvcl9pZCI6Ijc4MTU4OTk4MTI4MjExMjk3MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 91df515ea7b97e74ea400dc61dfae030dfc736049bff44d89ba3d9a03fc9a2e9 |
| hovercard-subject-tag | issue:1553382018 |
| 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/25062/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5710727696af4ee3be2864555df9083293e9e295218e8aa62a6ed82070e687e9/matplotlib/matplotlib/issues/25062 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5710727696af4ee3be2864555df9083293e9e295218e8aa62a6ed82070e687e9/matplotlib/matplotlib/issues/25062 |
| og:image:alt | Problem Trying to use imshow with unit-ful data and setting vmin/vmax with units fails. It would be great if this was possible! import matplotlib.pyplot as plt import numpy as np import pint ureg =... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dstansby |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| 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 | 07a982c1d40157c619b364352b704c3ce66bb332 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width