René's URL Explorer Experiment


Title: matplotlib.collections.QuadMesh.set_array() input arg format is weird and undocumented · Issue #15388 · matplotlib/matplotlib · GitHub

Open Graph Title: matplotlib.collections.QuadMesh.set_array() input arg format is weird and undocumented · Issue #15388 · matplotlib/matplotlib

X Title: matplotlib.collections.QuadMesh.set_array() input arg format is weird and undocumented · Issue #15388 · matplotlib/matplotlib

Description: Bug report Bug summary Trying to give matplotlib.collections.QuadMesh.set_array() the same argument as was used by matplotlib.axes.Axes.pcolormesh() results in an error. Moreover, the argument format depends on the shading; an argument t...

Open Graph Description: Bug report Bug summary Trying to give matplotlib.collections.QuadMesh.set_array() the same argument as was used by matplotlib.axes.Axes.pcolormesh() results in an error. Moreover, the argument form...

X Description: Bug report Bug summary Trying to give matplotlib.collections.QuadMesh.set_array() the same argument as was used by matplotlib.axes.Axes.pcolormesh() results in an error. Moreover, the argument form...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"matplotlib.collections.QuadMesh.set_array() input arg format is weird and undocumented","articleBody":"\u003c!--To help us understand and resolve your issue, please fill out the form to the best of your ability.--\u003e\r\n\u003c!--You can feel free to delete the sections that do not apply.--\u003e\r\n\r\n### Bug report\r\n\r\n**Bug summary**\r\n\r\nTrying to give `matplotlib.collections.QuadMesh.set_array()` the same argument as was used by `matplotlib.axes.Axes.pcolormesh()` results in an error. Moreover, the argument format depends on the shading; an argument that is correct for `shading='gouraud'` will be accepted and produce spurious graphics for `shading='flat'`. In my opinion, the user should be able to use the same argument format for the update (via `set_array` or another method if that causes backwards compatibility issues) than used for creation (via `pcolormesh`), and not have to care about the shading when setting the data.\r\n\r\nIt was raised in [a StackOverflow post from 2013](https://stackoverflow.com/questions/18797175/animation-with-pcolormesh-routine-in-matplotlib-how-do-i-initialize-the-data) and the top answer (from 2015) gives workarounds, but I did not find anything in the issue tracker (here).  It should at least be documented, [the current doc](https://matplotlib.org/3.1.1/api/collections_api.html?highlight=collections%20quadmesh%20set_array#matplotlib.collections.QuadMesh.set_array) only says \"Set the image array from numpy array A\".\r\n\r\n\u003c!--A short 1-2 sentences that succinctly describes the bug--\u003e\r\n\r\n**Code for reproduction**\r\n\r\n\u003c!--A minimum code snippet required to reproduce the bug.\r\nPlease make sure to minimize the number of dependencies required, and provide\r\nany necessary plotted data.\r\nAvoid using threads, as Matplotlib is (explicitly) not thread-safe.--\u003e\r\n\r\n```python\r\nimport numpy as np\r\nimport matplotlib.pyplot as plt\r\n\r\n\r\ndef f(X, Y, t=0):\r\n    return np.sin(X+t*np.pi)*np.sin(Y)\r\n\r\nxmin, xmax = 0.0, 4*np.pi\r\nymin, ymax = 0.0, 5*np.pi\r\nNx, Ny = 50, 40\r\nx, y = np.linspace(xmin, xmax, num=Nx), np.linspace(ymin, ymax, num=Ny)\r\nX, Y = np.meshgrid(x, y, indexing='ij')\r\nzstart = f(X, Y)\r\n\r\nrun_number = np.random.rand()\r\n\r\n# Intialize figure stuff\r\nfig = plt.figure()\r\naxs = [\r\n    plt.subplot(221, title='control flat'),\r\n    plt.subplot(222, title='test flat'),\r\n    plt.subplot(223, title='control gouraud'),\r\n    plt.subplot(224, title='test gouraud'),\r\n    ]\r\n\r\ndef drawcmesh(X, Y, z, ax, shading):\r\n    ax.set_xlim(left=xmin, right=xmax)\r\n    ax.set_ylim(bottom=ymin, top=ymax)\r\n    cmesh = ax.pcolormesh(X, Y, z,\r\n                          shading=shading, vmin=-1.5, vmax=1.5, cmap='hot')\r\n    return cmesh\r\n\r\n\r\n\r\nzstart = f(X, Y)\r\nperm_mesh = [\r\n    drawcmesh(X, Y, zstart, axs[1], shading='flat'),\r\n    drawcmesh(X, Y, zstart, axs[3], shading='gouraud')\r\n    ]\r\ndrawcmesh(X, Y, zstart, axs[0], shading='flat')\r\ndrawcmesh(X, Y, zstart, axs[2], shading='gouraud')\r\n\r\ndef update(t):\r\n    z = f(X, Y, t)\r\n\r\n    for i in range(4):\r\n        ax = axs[i]\r\n        if i\u003c2:\r\n            shading='flat'\r\n        else:\r\n            shading='gouraud'\r\n\r\n        if i%2 == 0:\r\n            # Control case: redraw by hand\r\n            axs[i].clear()\r\n            drawcmesh(X, Y, z, axs[i], shading=shading)\r\n            axs[i].set_title('control {}'.format(shading))\r\n\r\n        if i==1:\r\n            # Flat shading\r\n\r\n            # # The following would copy the syntax of plt.pcolormesh() but it\r\n            # # results in an error\r\n            # perm_mesh[0].set_array(z)\r\n\r\n            # The following does not error out but the plot is later incorrect\r\n            perm_mesh[0].set_array(z.ravel())\r\n\r\n            # # The following works\r\n            # perm_mesh[0].set_array(z[:-1, :-1].ravel())\r\n\r\n        if i==3:\r\n            # Gouraud shading\r\n\r\n            # # The following would copy the syntax of plt.pcolormesh() but it\r\n            # # results in an error\r\n            # perm_mesh[1].set_array(z)\r\n\r\n            # The following works\r\n            perm_mesh[1].set_array(z.ravel())\r\n\r\n            # # The following results in an error at draw time:\r\n\r\n            \r\n            # perm_mesh[1].set_array(z[:-1, :-1].ravel())\r\n\r\n# # Uncomment this to check that the initial drawing for the test case is correct\r\n# plt.show(block=True)\r\n\r\nplt.show(block=False)\r\nfor t in np.linspace(0.0, 4.0, num=50):\r\n    update(t)\r\n    fig.canvas.draw()\r\n    fig.canvas.flush_events()\r\n```\r\n\r\n**Results**\r\nCf commented code under `# Flat shading` and `# Gouraud shading` in the source for the various possibilities.\r\n\r\nSpurious graphics for flat shading:\r\n\r\n\u003cimg width=\"561\" alt=\"test-shadings\" src=\"https://user-images.githubusercontent.com/28686753/66308548-b0194600-e907-11e9-97e6-ad61452022d2.PNG\"\u003e\r\n\r\n\r\n\r\n\r\nError given by gouraud shading when dimensions do not match:\r\n\r\n\r\n```\r\n\u003ccurrent file\u003e, line 93, in \u003cmodule\u003e\r\n    fig.canvas.draw()\r\nFile \"\u003canaconda-site-packages\u003e\\matplotlib\\backends\\backend_agg.py\", line 388, in draw\r\n    self.figure.draw(self.renderer)\r\nFile \"\u003canaconda-site-packages\u003e\\matplotlib\\artist.py\", line 38, in draw_wrapper\r\n    return draw(artist, renderer, *args, **kwargs)\r\nFile \"\u003canaconda-site-packages\u003e\\matplotlib\\figure.py\", line 1709, in draw\r\n    renderer, self, artists, self.suppressComposite)\r\nFile \"\u003canaconda-site-packages\u003e\\matplotlib\\image.py\", line 135, in _draw_list_compositing_images\r\n    a.draw(renderer)\r\nFile \"\u003canaconda-site-packages\u003e\\matplotlib\\artist.py\", line 38, in draw_wrapper\r\n    return draw(artist, renderer, *args, **kwargs)\r\nFile \"\u003canaconda-site-packages\u003e\\matplotlib\\axes\\_base.py\", line 2647, in draw\r\n    mimage._draw_list_compositing_images(renderer, self, artists)\r\nFile \"\u003canaconda-site-packages\u003e\\matplotlib\\image.py\", line 135, in _draw_list_compositing_images\r\n    a.draw(renderer)\r\nFile \"\u003canaconda-site-packages\u003e\\matplotlib\\artist.py\", line 38, in draw_wrapper\r\n    return draw(artist, renderer, *args, **kwargs)\r\nFile \"\u003canaconda-site-packages\u003e\\matplotlib\\collections.py\", line 2037, in draw\r\n    self._meshWidth, self._meshHeight, coordinates)\r\nFile \"\u003canaconda-site-packages\u003e\\matplotlib\\collections.py\", line 1985, in convert_mesh_to_triangles\r\n    c = self.get_facecolor().reshape((meshHeight + 1, meshWidth + 1, 4))\r\nValueError: cannot reshape array of size 7644 into shape (50,40,4)\r\n```\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: Win10\r\n  * Matplotlib version: 3.1.1 (from conda)\r\n  * Matplotlib backend (`print(matplotlib.get_backend())`): Qt5Agg\r\n  * Python version: 3.7.4\r\n","author":{"url":"https://github.com/Tigraan","@type":"Person","name":"Tigraan"},"datePublished":"2019-10-07T11:31:38.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":4},"url":"https://github.com/15388/matplotlib/issues/15388"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:68cebd5a-3570-2e4b-cea1-ca8ffc685540
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idA2E0:172D3F:263588A:33E13BE:6A548030
html-safe-noncecd585517c39084359f55606a1ac0ccf53f4e0655b31310f78ad3d631802f0fcd
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMkUwOjE3MkQzRjoyNjM1ODhBOjMzRTEzQkU6NkE1NDgwMzAiLCJ2aXNpdG9yX2lkIjoiNTMzNDI1NTE1MTgzMzQ0ODQ5NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacbcc0fb4840603c64d74368d597d1733d243e70436061aea7eb7e2d3cb9715dfc
hovercard-subject-tagissue:503393496
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/15388/issue_layout
twitter:imagehttps://opengraph.githubassets.com/d00302a47402546ccff228077e607bae42df8a4f9f7aba466d42309c337181d8/matplotlib/matplotlib/issues/15388
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/d00302a47402546ccff228077e607bae42df8a4f9f7aba466d42309c337181d8/matplotlib/matplotlib/issues/15388
og:image:altBug report Bug summary Trying to give matplotlib.collections.QuadMesh.set_array() the same argument as was used by matplotlib.axes.Axes.pcolormesh() results in an error. Moreover, the argument form...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameTigraan
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
release6d28624802c2f7d9500239dd6870ed7031b7353b
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/matplotlib/matplotlib/issues/15388#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmatplotlib%2Fmatplotlib%2Fissues%2F15388
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%2F15388
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/15388
Reloadhttps://github.com/matplotlib/matplotlib/issues/15388
Reloadhttps://github.com/matplotlib/matplotlib/issues/15388
Please reload this pagehttps://github.com/matplotlib/matplotlib/issues/15388
matplotlib https://github.com/matplotlib
matplotlibhttps://github.com/matplotlib/matplotlib
Please reload this pagehttps://github.com/matplotlib/matplotlib/issues/15388
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
matplotlib.collections.QuadMesh.set_array() input arg format is weird and undocumentedhttps://github.com/matplotlib/matplotlib/issues/15388#top
API: consistencyConsistency of the matplotlib API, including naming, behavior, defaults, …https://github.com/matplotlib/matplotlib/issues?q=state%3Aopen%20label%3A%22API%3A%20consistency%22
Documentationhttps://github.com/matplotlib/matplotlib/issues?q=state%3Aopen%20label%3A%22Documentation%22
v3.7.0https://github.com/matplotlib/matplotlib/milestone/70
https://github.com/Tigraan
Tigraanhttps://github.com/Tigraan
on Oct 7, 2019https://github.com/matplotlib/matplotlib/issues/15388#issue-503393496
a StackOverflow post from 2013https://stackoverflow.com/questions/18797175/animation-with-pcolormesh-routine-in-matplotlib-how-do-i-initialize-the-data
the current dochttps://matplotlib.org/3.1.1/api/collections_api.html?highlight=collections%20quadmesh%20set_array#matplotlib.collections.QuadMesh.set_array
https://user-images.githubusercontent.com/28686753/66308548-b0194600-e907-11e9-97e6-ad61452022d2.PNG
API: consistencyConsistency of the matplotlib API, including naming, behavior, defaults, …https://github.com/matplotlib/matplotlib/issues?q=state%3Aopen%20label%3A%22API%3A%20consistency%22
Documentationhttps://github.com/matplotlib/matplotlib/issues?q=state%3Aopen%20label%3A%22Documentation%22
v3.7.0https://github.com/matplotlib/matplotlib/milestone/70
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.