Title: [DOC]: Using matplotlib.pyplot.pcolormesh with shading='flat' · Issue #31320 · matplotlib/matplotlib · GitHub
Open Graph Title: [DOC]: Using matplotlib.pyplot.pcolormesh with shading='flat' · Issue #31320 · matplotlib/matplotlib
X Title: [DOC]: Using matplotlib.pyplot.pcolormesh with shading='flat' · Issue #31320 · matplotlib/matplotlib
Description: Bug summary When using plt.pcolormesh on an array of size C=(10,10), with two coordinates of size X=(10) and Y=(10), the last value C[-1,-1] isn't silently dropped as your documentation says. The documentation : "If X, Y and C have equal...
Open Graph Description: Bug summary When using plt.pcolormesh on an array of size C=(10,10), with two coordinates of size X=(10) and Y=(10), the last value C[-1,-1] isn't silently dropped as your documentation says. The d...
X Description: Bug summary When using plt.pcolormesh on an array of size C=(10,10), with two coordinates of size X=(10) and Y=(10), the last value C[-1,-1] isn't silently dropped as your documentation says. T...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/31320
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[DOC]: Using matplotlib.pyplot.pcolormesh with shading='flat'","articleBody":"### Bug summary\n\nWhen using plt.pcolormesh on an array of size C=(10,10), with two coordinates of size X=(10) and Y=(10), the last value C[-1,-1] isn't silently dropped as your documentation says.\n\nThe documentation :\n\"If X, Y and C have equal dimensions, a warning will be raised and the last row and column of C will be ignored.\"\nextracted from http://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.pcolormesh.html\n\nThe error I get when using xarrays wrapper of pcolormesh:\n``` bash\nTraceback (most recent call last):\n File \"/home/AD278604/deltavar-GyselaX/test.py\", line 21, in \u003cmodule\u003e\n da.plot.pcolormesh(shading=\"flat\", infer_intervals=False)\n ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/data/gyselarunner/gyselalibxx-env-shared/.spack-env/view/lib/python3.14/site-packages/xarray/plot/accessor.py\", line 784, in pcolormesh\n return dataarray_plot.pcolormesh(self._da, *args, **kwargs)\n ~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/data/gyselarunner/gyselalibxx-env-shared/.spack-env/view/lib/python3.14/site-packages/xarray/plot/dataarray_plot.py\", line 1606, in newplotfunc\n primitive = plotfunc(\n xplt,\n ...\u003c7 lines\u003e...\n **kwargs,\n )\n File \"/data/gyselarunner/gyselalibxx-env-shared/.spack-env/view/lib/python3.14/site-packages/xarray/plot/dataarray_plot.py\", line 2315, in pcolormesh\n primitive = ax.pcolormesh(x, y, z, **kwargs)\n File \"/data/gyselarunner/gyselalibxx-env-shared/.spack-env/view/lib/python3.14/site-packages/matplotlib/__init__.py\", line 1524, in inner\n return func(\n ax,\n *map(cbook.sanitize_sequence, args),\n **{k: cbook.sanitize_sequence(v) for k, v in kwargs.items()})\n File \"/data/gyselarunner/gyselalibxx-env-shared/.spack-env/view/lib/python3.14/site-packages/matplotlib/axes/_axes.py\", line 6528, in pcolormesh\n X, Y, C, shading = self._pcolorargs('pcolormesh', *args,\n ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^\n shading=shading, kwargs=kwargs)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/data/gyselarunner/gyselalibxx-env-shared/.spack-env/view/lib/python3.14/site-packages/matplotlib/axes/_axes.py\", line 6060, in _pcolorargs\n raise TypeError(f\"Dimensions of C {C.shape} should\"\n ...\u003c2 lines\u003e...\n f\" see help({funcname})\")\nTypeError: Dimensions of C (2, 2) should be one smaller than X(2) and Y(2) while using shading='flat' see help(pcolormesh)\n```\n\n### Code for reproduction\n\n```Python\nimport xarray as xr\nimport numpy as np\nimport matplotlib.pyplot as plt\n\nC = np.array([[0, 1],\n [2, 3]])\nX = [0, 1]\nY = [0, 1]\n\nda = xr.DataArray(\n data=C,\n coords={\"Y\": Y, \"X\": X},\n dims=[\"Y\", \"X\"]\n)\n\nprint(\"Data shape:\", da.shape)\nprint(\"X shape:\", da[\"X\"].shape)\nprint(\"Y shape:\", da[\"Y\"].shape)\nprint(\"-\" * 50)\n\nda.plot.pcolormesh(shading=\"flat\", infer_intervals=False)\nplt.show()\n```\n\n### Actual outcome\n\n``` bash\nTraceback (most recent call last):\n File \"/home/AD278604/deltavar-GyselaX/test.py\", line 21, in \u003cmodule\u003e\n da.plot.pcolormesh(shading=\"flat\", infer_intervals=False)\n ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/data/gyselarunner/gyselalibxx-env-shared/.spack-env/view/lib/python3.14/site-packages/xarray/plot/accessor.py\", line 784, in pcolormesh\n return dataarray_plot.pcolormesh(self._da, *args, **kwargs)\n ~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/data/gyselarunner/gyselalibxx-env-shared/.spack-env/view/lib/python3.14/site-packages/xarray/plot/dataarray_plot.py\", line 1606, in newplotfunc\n primitive = plotfunc(\n xplt,\n ...\u003c7 lines\u003e...\n **kwargs,\n )\n File \"/data/gyselarunner/gyselalibxx-env-shared/.spack-env/view/lib/python3.14/site-packages/xarray/plot/dataarray_plot.py\", line 2315, in pcolormesh\n primitive = ax.pcolormesh(x, y, z, **kwargs)\n File \"/data/gyselarunner/gyselalibxx-env-shared/.spack-env/view/lib/python3.14/site-packages/matplotlib/__init__.py\", line 1524, in inner\n return func(\n ax,\n *map(cbook.sanitize_sequence, args),\n **{k: cbook.sanitize_sequence(v) for k, v in kwargs.items()})\n File \"/data/gyselarunner/gyselalibxx-env-shared/.spack-env/view/lib/python3.14/site-packages/matplotlib/axes/_axes.py\", line 6528, in pcolormesh\n X, Y, C, shading = self._pcolorargs('pcolormesh', *args,\n ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^\n shading=shading, kwargs=kwargs)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/data/gyselarunner/gyselalibxx-env-shared/.spack-env/view/lib/python3.14/site-packages/matplotlib/axes/_axes.py\", line 6060, in _pcolorargs\n raise TypeError(f\"Dimensions of C {C.shape} should\"\n ...\u003c2 lines\u003e...\n f\" see help({funcname})\")\nTypeError: Dimensions of C (2, 2) should be one smaller than X(2) and Y(2) while using shading='flat' see help(pcolormesh)\n```\n\n### Expected outcome\n\nthe plot, and matplotlib silently dropping the last value of C\n\n### Additional information\n\n_No response_\n\n### Operating system\n\nDebian\n\n### Matplotlib Version\n\n3.10.7\n\n### Matplotlib Backend\n\nagg\n\n### Python version\n\n3.14\n\n### Jupyter version\n\n_No response_\n\n### Installation\n\npip","author":{"url":"https://github.com/ArielDeVora","@type":"Person","name":"ArielDeVora"},"datePublished":"2026-03-17T12:54:54.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/31320/matplotlib/issues/31320"}
| 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:c4ea5ef5-8666-c87e-d4bb-12bf921eb1e7 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9994:3A401E:CE9D11:1159F32:6A52C396 |
| html-safe-nonce | ff1da23f97136e2bb724ee85ab75b42661da09d942ab9ff535a6a47988b9586c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5OTk0OjNBNDAxRTpDRTlEMTE6MTE1OUYzMjo2QTUyQzM5NiIsInZpc2l0b3JfaWQiOiI3NDM4OTgwNTI3Nzk1OTEzNjIyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 0e291b9712adb2ee33b4bb9d3d4b01b8d21c14d9b6db2032e96a48f586424f98 |
| hovercard-subject-tag | issue:4088377294 |
| 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/31320/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f4c2fb25ee0827a1e7600dd8ebd6beca20af21f317357c6335e5f4d89dc8e610/matplotlib/matplotlib/issues/31320 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f4c2fb25ee0827a1e7600dd8ebd6beca20af21f317357c6335e5f4d89dc8e610/matplotlib/matplotlib/issues/31320 |
| og:image:alt | Bug summary When using plt.pcolormesh on an array of size C=(10,10), with two coordinates of size X=(10) and Y=(10), the last value C[-1,-1] isn't silently dropped as your documentation says. The d... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ArielDeVora |
| 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