René's URL Explorer Experiment


Title: Imshow breaks if given a unyt_array input · Issue #18077 · matplotlib/matplotlib · GitHub

Open Graph Title: Imshow breaks if given a unyt_array input · Issue #18077 · matplotlib/matplotlib

X Title: Imshow breaks if given a unyt_array input · Issue #18077 · matplotlib/matplotlib

Description: Bug report Bug summary matplotlib.pyplot.imshow doesn't seem to play nicely with unyt_arrays like other plotting functions do. Description This problem was originally reported on unyt (yt-project/unyt#161) According to unyt's documentati...

Open Graph Description: Bug report Bug summary matplotlib.pyplot.imshow doesn't seem to play nicely with unyt_arrays like other plotting functions do. Description This problem was originally reported on unyt (yt-project/u...

X Description: Bug report Bug summary matplotlib.pyplot.imshow doesn't seem to play nicely with unyt_arrays like other plotting functions do. Description This problem was originally reported on unyt (yt-proje...

Opengraph URL: https://github.com/matplotlib/matplotlib/issues/18077

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Imshow breaks if given a unyt_array input","articleBody":"### Bug report\r\n\r\n**Bug summary**\r\n`matplotlib.pyplot.imshow` doesn't seem to play nicely with `unyt_arrays` like other plotting functions do.\r\n\r\n\r\n\r\n\r\n\r\n### Description\r\n\r\nThis problem was originally reported on unyt (https://github.com/yt-project/unyt/issues/161)\r\nAccording to unyt's documentation matplotlib is \"unyt_aware\", but it seems that some plotting functions are not well behaved.\r\n\r\n\r\n### What I Did\r\n**Code for reproduction**\r\n```python\r\nimport unyt\r\nimport numpy as np\r\nfrom matplotlib import pyplot as plt\r\n\r\narr = unyt.unyt_array(np.ones((16, 16)), \"g/cm**3\")\r\nplt.pcolormesh(arr) # works\r\nplt.contourf(arr) # works\r\nplt.imshow(arr) # breaks\r\n\u003e\u003e UnitOperationError: The \u003cufunc 'add'\u003e operator for unyt_arrays with units \"g/cm**3\" \r\n(dimensions \"(mass)/(length)**3\") and \"dimensionless\" (dimensions \"1\") is not well defined.\r\n```\r\n\r\n**Actual outcome**\r\n\r\nFull trace\r\n\r\n```\r\nUnitOperationError                        Traceback (most recent call last)\r\n\u003cipython-input-9-7192cbd0f805\u003e in \u003cmodule\u003e\r\n----\u003e 1 plt.savefig(\"hello\")\r\n\r\n~/miniconda3/envs/mpl_latest/lib/python3.8/site-packages/matplotlib/pyplot.py in savefig(*args, **kwargs)\r\n    840 def savefig(*args, **kwargs):\r\n    841     fig = gcf()\r\n--\u003e 842     res = fig.savefig(*args, **kwargs)\r\n    843     fig.canvas.draw_idle()   # need this if 'transparent=True' to reset colors\r\n    844     return res\r\n\r\n~/miniconda3/envs/mpl_latest/lib/python3.8/site-packages/matplotlib/figure.py in savefig(self, fname, transparent, **kwargs)\r\n   2309                 patch.set_edgecolor('none')\r\n   2310\r\n-\u003e 2311         self.canvas.print_figure(fname, **kwargs)\r\n   2312\r\n   2313         if transparent:\r\n\r\n~/miniconda3/envs/mpl_latest/lib/python3.8/site-packages/matplotlib/backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, pad_inches, bbox_extra_artists, backend, **kwargs)\r\n   2208\r\n   2209             try:\r\n-\u003e 2210                 result = print_method(\r\n   2211                     filename,\r\n   2212                     dpi=dpi,\r\n\r\n~/miniconda3/envs/mpl_latest/lib/python3.8/site-packages/matplotlib/backend_bases.py in wrapper(*args, **kwargs)\r\n   1637             kwargs.pop(arg)\r\n   1638\r\n-\u003e 1639         return func(*args, **kwargs)\r\n   1640\r\n   1641     return wrapper\r\n\r\n~/miniconda3/envs/mpl_latest/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py in print_png(self, filename_or_obj, metadata, pil_kwargs, *args)\r\n    507             *metadata*, including the default 'Software' key.\r\n    508         \"\"\"\r\n--\u003e 509         FigureCanvasAgg.draw(self)\r\n    510         mpl.image.imsave(\r\n    511             filename_or_obj, self.buffer_rgba(), format=\"png\", origin=\"upper\",\r\n\r\n~/miniconda3/envs/mpl_latest/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py in draw(self)\r\n    405              (self.toolbar._wait_cursor_for_draw_cm() if self.toolbar\r\n    406               else nullcontext()):\r\n--\u003e 407             self.figure.draw(self.renderer)\r\n    408             # A GUI class may be need to update a window using this draw, so\r\n    409             # don't forget to call the superclass.\r\n\r\n~/miniconda3/envs/mpl_latest/lib/python3.8/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)\r\n     39                 renderer.start_filter()\r\n     40\r\n---\u003e 41             return draw(artist, renderer, *args, **kwargs)\r\n     42         finally:\r\n     43             if artist.get_agg_filter() is not None:\r\n\r\n~/miniconda3/envs/mpl_latest/lib/python3.8/site-packages/matplotlib/figure.py in draw(self, renderer)\r\n   1861\r\n   1862             self.patch.draw(renderer)\r\n-\u003e 1863             mimage._draw_list_compositing_images(\r\n   1864                 renderer, self, artists, self.suppressComposite)\r\n   1865\r\n\r\n~/miniconda3/envs/mpl_latest/lib/python3.8/site-packages/matplotlib/image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)\r\n    130     if not_composite or not has_images:\r\n    131         for a in artists:\r\n--\u003e 132             a.draw(renderer)\r\n    133     else:\r\n    134         # Composite any adjacent images together\r\n\r\n~/miniconda3/envs/mpl_latest/lib/python3.8/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)\r\n     39                 renderer.start_filter()\r\n     40\r\n---\u003e 41             return draw(artist, renderer, *args, **kwargs)\r\n     42         finally:\r\n     43             if artist.get_agg_filter() is not None:\r\n\r\n~/miniconda3/envs/mpl_latest/lib/python3.8/site-packages/matplotlib/cbook/deprecation.py in wrapper(*inner_args, **inner_kwargs)\r\n    409                          else deprecation_addendum,\r\n    410                 **kwargs)\r\n--\u003e 411         return func(*inner_args, **inner_kwargs)\r\n    412\r\n    413     return wrapper\r\n\r\n~/miniconda3/envs/mpl_latest/lib/python3.8/site-packages/matplotlib/axes/_base.py in draw(self, renderer, inframe)\r\n   2746             renderer.stop_rasterizing()\r\n   2747\r\n-\u003e 2748         mimage._draw_list_compositing_images(renderer, self, artists)\r\n   2749\r\n   2750         renderer.close_group('axes')\r\n\r\n~/miniconda3/envs/mpl_latest/lib/python3.8/site-packages/matplotlib/image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)\r\n    130     if not_composite or not has_images:\r\n    131         for a in artists:\r\n--\u003e 132             a.draw(renderer)\r\n    133     else:\r\n    134         # Composite any adjacent images together\r\n\r\n~/miniconda3/envs/mpl_latest/lib/python3.8/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)\r\n     39                 renderer.start_filter()\r\n     40\r\n---\u003e 41             return draw(artist, renderer, *args, **kwargs)\r\n     42         finally:\r\n     43             if artist.get_agg_filter() is not None:\r\n\r\n~/miniconda3/envs/mpl_latest/lib/python3.8/site-packages/matplotlib/image.py in draw(self, renderer, *args, **kwargs)\r\n    636                 renderer.draw_image(gc, l, b, im, trans)\r\n    637         else:\r\n--\u003e 638             im, l, b, trans = self.make_image(\r\n    639                 renderer, renderer.get_image_magnification())\r\n    640             if im is not None:\r\n\r\n~/miniconda3/envs/mpl_latest/lib/python3.8/site-packages/matplotlib/image.py in make_image(self, renderer, magnification, unsampled)\r\n    921         clip = ((self.get_clip_box() or self.axes.bbox) if self.get_clip_on()\r\n    922                 else self.figure.bbox)\r\n--\u003e 923         return self._make_image(self._A, bbox, transformed_bbox, clip,\r\n    924                                 magnification, unsampled=unsampled)\r\n    925\r\n\r\n~/miniconda3/envs/mpl_latest/lib/python3.8/site-packages/matplotlib/image.py in _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification, unsampled, round_to_pixel_border)\r\n    446                 self.norm.autoscale_None(A)\r\n    447                 dv = np.float64(self.norm.vmax) - np.float64(self.norm.vmin)\r\n--\u003e 448                 vmid = self.norm.vmin + dv / 2\r\n    449                 fact = 1e7 if scaled_dtype == np.float64 else 1e4\r\n    450                 newmin = vmid - dv * fact\r\n\r\n~/miniconda3/envs/mpl_latest/lib/python3.8/site-packages/numpy/ma/core.py in __add__(self, other)\r\n   4136         if self._delegate_binop(other):\r\n   4137             return NotImplemented\r\n-\u003e 4138         return add(self, other)\r\n   4139\r\n   4140     def __radd__(self, other):\r\n\r\n~/miniconda3/envs/mpl_latest/lib/python3.8/site-packages/numpy/ma/core.py in __call__(self, a, b, *args, **kwargs)\r\n   1019         with np.errstate():\r\n   1020             np.seterr(divide='ignore', invalid='ignore')\r\n-\u003e 1021             result = self.f(da, db, *args, **kwargs)\r\n   1022         # Get the mask for the result\r\n   1023         (ma, mb) = (getmask(a), getmask(b))\r\n\r\n~/miniconda3/envs/mpl_latest/lib/python3.8/site-packages/unyt/array.py in __array_ufunc__(self, ufunc, method, *inputs, **kwargs)\r\n   1737                                     raise UnitOperationError(ufunc, u0, u1)\r\n   1738                         else:\r\n-\u003e 1739                             raise UnitOperationError(ufunc, u0, u1)\r\n   1740                     conv, offset = u1.get_conversion_factor(u0, inp1.dtype)\r\n   1741                     new_dtype = np.dtype(\"f\" + str(inp1.dtype.itemsize))\r\n\r\nUnitOperationError: The \u003cufunc 'add'\u003e operator for unyt_arrays with units \"g/cm**3\" (dimensions \"(mass)/(length)**3\") and \"dimensionless\" (dimensions \"1\") is not well defined\r\n```\r\n\r\n**Expected outcome**\r\nA usable figure :)\r\n\r\n**Matplotlib version**\r\n\u003c!--Please specify your platform and versions of the relevant libraries you are using:--\u003e\r\n  * Operating system: MacOS\r\n  * Matplotlib version: 3.3.0\r\n  * Matplotlib backend (`print(matplotlib.get_backend())`): MacOSX\r\n  * Python version: 3.8.3\r\n  * Jupyter version (if applicable):\r\n  * Other libraries: IPython 7.16.1\r\n\r\nmpl installed via cona (Conda-forge channel)\r\n\r\n","author":{"url":"https://github.com/neutrinoceros","@type":"Person","name":"neutrinoceros"},"datePublished":"2020-07-26T15:15:55.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":6},"url":"https://github.com/18077/matplotlib/issues/18077"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:04817472-7bf4-7665-476d-2c6ffd5e81aa
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idD2A4:381414:561EF8:73C6E7:6A534487
html-safe-noncef85cd7cdebc67f5b9e77cf068d0004798c95d5935409dd98be66bcce0c98a700
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMkE0OjM4MTQxNDo1NjFFRjg6NzNDNkU3OjZBNTM0NDg3IiwidmlzaXRvcl9pZCI6IjE2NzQwMzI0OTExNjQ1NTAyNzkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac95cca988f710d62fdade5c590444e8602adcb74caa2cfe9acc2bb9e657d345a6
hovercard-subject-tagissue:665800695
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/matplotlib/matplotlib/18077/issue_layout
twitter:imagehttps://opengraph.githubassets.com/8a635308e72982a2ce37d8b76fdba39d66b91461851219c651ed29a0584f1fcd/matplotlib/matplotlib/issues/18077
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/8a635308e72982a2ce37d8b76fdba39d66b91461851219c651ed29a0584f1fcd/matplotlib/matplotlib/issues/18077
og:image:altBug report Bug summary matplotlib.pyplot.imshow doesn't seem to play nicely with unyt_arrays like other plotting functions do. Description This problem was originally reported on unyt (yt-project/u...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameneutrinoceros
hostnamegithub.com
expected-hostnamegithub.com
Noneb9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb
turbo-cache-controlno-preview
go-importgithub.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git
octolytics-dimension-user_id215947
octolytics-dimension-user_loginmatplotlib
octolytics-dimension-repository_id1385122
octolytics-dimension-repository_nwomatplotlib/matplotlib
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id1385122
octolytics-dimension-repository_network_root_nwomatplotlib/matplotlib
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release07a982c1d40157c619b364352b704c3ce66bb332
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/matplotlib/matplotlib/issues/18077#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmatplotlib%2Fmatplotlib%2Fissues%2F18077
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmatplotlib%2Fmatplotlib%2Fissues%2F18077
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=matplotlib%2Fmatplotlib
Reloadhttps://github.com/matplotlib/matplotlib/issues/18077
Reloadhttps://github.com/matplotlib/matplotlib/issues/18077
Reloadhttps://github.com/matplotlib/matplotlib/issues/18077
Please reload this pagehttps://github.com/matplotlib/matplotlib/issues/18077
matplotlib https://github.com/matplotlib
matplotlibhttps://github.com/matplotlib/matplotlib
Please reload this pagehttps://github.com/matplotlib/matplotlib/issues/18077
Notifications https://github.com/login?return_to=%2Fmatplotlib%2Fmatplotlib
Fork 8.4k https://github.com/login?return_to=%2Fmatplotlib%2Fmatplotlib
Star 23k https://github.com/login?return_to=%2Fmatplotlib%2Fmatplotlib
Code https://github.com/matplotlib/matplotlib
Issues 1.1k https://github.com/matplotlib/matplotlib/issues
Pull requests 408 https://github.com/matplotlib/matplotlib/pulls
Actions https://github.com/matplotlib/matplotlib/actions
Projects https://github.com/matplotlib/matplotlib/projects
Wiki https://github.com/matplotlib/matplotlib/wiki
Security and quality 0 https://github.com/matplotlib/matplotlib/security
Insights https://github.com/matplotlib/matplotlib/pulse
Code https://github.com/matplotlib/matplotlib
Issues https://github.com/matplotlib/matplotlib/issues
Pull requests https://github.com/matplotlib/matplotlib/pulls
Actions https://github.com/matplotlib/matplotlib/actions
Projects https://github.com/matplotlib/matplotlib/projects
Wiki https://github.com/matplotlib/matplotlib/wiki
Security and quality https://github.com/matplotlib/matplotlib/security
Insights https://github.com/matplotlib/matplotlib/pulse
#18286https://github.com/matplotlib/matplotlib/pull/18286
Imshow breaks if given a unyt_array inputhttps://github.com/matplotlib/matplotlib/issues/18077#top
#18286https://github.com/matplotlib/matplotlib/pull/18286
topic: units and array ducktypeshttps://github.com/matplotlib/matplotlib/issues?q=state%3Aopen%20label%3A%22topic%3A%20units%20and%20array%20ducktypes%22
v3.4.0https://github.com/matplotlib/matplotlib/milestone/53
https://github.com/neutrinoceros
neutrinoceroshttps://github.com/neutrinoceros
on Jul 26, 2020https://github.com/matplotlib/matplotlib/issues/18077#issue-665800695
yt-project/unyt#161https://github.com/yt-project/unyt/issues/161
topic: units and array ducktypeshttps://github.com/matplotlib/matplotlib/issues?q=state%3Aopen%20label%3A%22topic%3A%20units%20and%20array%20ducktypes%22
v3.4.0https://github.com/matplotlib/matplotlib/milestone/53
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.