Title: [Bug]: contour/contourf silently produces nonsense levels when Z is constant (zmin == zmax) · Issue #31493 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: contour/contourf silently produces nonsense levels when Z is constant (zmin == zmax) · Issue #31493 · matplotlib/matplotlib
X Title: [Bug]: contour/contourf silently produces nonsense levels when Z is constant (zmin == zmax) · Issue #31493 · matplotlib/matplotlib
Description: Bug summary When Z has no variation (all values are equal), contour and contourf silently produce multiple identical levels and render empty collections with no warning to the user. The plot appears blank or broken with no indication of ...
Open Graph Description: Bug summary When Z has no variation (all values are equal), contour and contourf silently produce multiple identical levels and render empty collections with no warning to the user. The plot appear...
X Description: Bug summary When Z has no variation (all values are equal), contour and contourf silently produce multiple identical levels and render empty collections with no warning to the user. The plot appear...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/31493
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: contour/contourf silently produces nonsense levels when Z is constant (zmin == zmax)","articleBody":"### Bug summary\n\n**When Z has no variation (all values are equal), contour and contourf silently \nproduce multiple identical levels and render empty collections with no warning \nto the user. The plot appears blank or broken with no indication of why.**\n\n### Code for reproduction\n\n```Python\nimport numpy as np\nimport matplotlib.pyplot as plt\n\nZ = np.ones((10, 10)) * 5.0 # constant Z\n\nfig, (ax1, ax2) = plt.subplots(1, 2)\ncs1 = ax1.contour(np.linspace(0, 1, 10), np.linspace(0, 1, 10), Z)\ncs2 = ax2.contourf(np.linspace(0, 1, 10), np.linspace(0, 1, 10), Z)\n\nprint(f\"contour levels: {cs1.levels}\") # [5. 5. 5. 5. 5. 5. 5. 5.]\nprint(f\"contourf levels: {cs2.levels}\") # [5. 5. 5. 5. 5. 5. 5. 5.]\nprint(f\"contour paths: {cs1.get_paths()}\") # all empty\n```\n\n### Actual outcome\n\ncontour levels: [5. 5. 5. 5. 5. 5. 5. 5.]\ncontourf levels: [5. 5. 5. 5. 5. 5. 5. 5.]\nNo UserWarning raised. Plot is blank. User has no indication of why.\n\n### Expected outcome\n\nA UserWarning should be raised:\n\"No contour levels can be computed: Z has no variation (min == max == 5.0).\"\n\nSimilar to the existing warning \"No contour levels were found within the data \nrange\" which fires when user-supplied levels are out of range — but that \nwarning never fires for the auto-level case when zmin == zmax.\n\n### Additional information\n\nRoot cause is in contour.py around line 1364-1370. After zmin and zmax are \ncomputed from Z, there is no check for zmin == zmax before _process_contour_level_args \nis called. When zmin == zmax, MaxNLocator.tick_values() returns identical values, \nthe i1 - i0 \u003c 3 fallback at line 1002 triggers, and the full array of identical \nlevels is returned silently.\n\nThe fix is a one-block addition right after line 1365:\n\n if self.zmin == self.zmax:\n _api.warn_external(\n f\"No contour levels can be computed: Z has no variation \"\n f\"(min == max == {self.zmin}).\"\n )\n\nThis is consistent with the logscale warning pattern directly below it.\n\n### Operating system\n\nLinux\n\n### Matplotlib Version\n\n3.10.8\n\n### Matplotlib Backend\n\n_No response_\n\n### Python version\n\n_No response_\n\n### Jupyter version\n\n_No response_\n\n### Installation\n\nNone","author":{"url":"https://github.com/buddy0452004","@type":"Person","name":"buddy0452004"},"datePublished":"2026-04-13T07:18:06Z","url":"https://github.com/matplotlib/matplotlib/issues/31493"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:243e48d3-8af2-9c1d-49fc-55fe4d687ffd |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AEBC:3F8E32:E46EF3:135BB7D:6B06535E |
| html-safe-nonce | 44a58b8f9a2c4cdddd5ca9464854ab43e368fd7310610113b927a7a8f3190fd9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRUJDOjNGOEUzMjpFNDZFRjM6MTM1QkI3RDo2QjA2NTM1RSIsInZpc2l0b3JfaWQiOiI3NTcyMTc2OTk0MTg5MDcxMTk4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | c342136790e0376e7517de942e1997b04dc4d082c5a13849878c2bf2afe7b9f3 |
| hovercard-subject-tag | issue:4252139057 |
| 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/31493/issue_layout |
| twitter:image | https://opengraph.githubassets.com/25b2287427c94ca126c0bbf8e48bbbb2e9eba2cdb0d010217376ba9c464c5916/matplotlib/matplotlib/issues/31493 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/25b2287427c94ca126c0bbf8e48bbbb2e9eba2cdb0d010217376ba9c464c5916/matplotlib/matplotlib/issues/31493 |
| og:image:alt | Bug summary When Z has no variation (all values are equal), contour and contourf silently produce multiple identical levels and render empty collections with no warning to the user. The plot appear... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | buddy0452004 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 772b6997ca4daa0428dd49a25d76052e765555ae560fe9c88517eb828bbd861e |
| 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 | f1f9a08f7c769a37f1dfc18ad43d463c222a7eea |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width