Title: [Bug]: Colorbar get_ticks() return the incorrect array · Issue #31086 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: Colorbar get_ticks() return the incorrect array · Issue #31086 · matplotlib/matplotlib
X Title: [Bug]: Colorbar get_ticks() return the incorrect array · Issue #31086 · matplotlib/matplotlib
Description: Bug summary When creating a colorbar using a ScalarMappable with the NoNorm normalization and a discrete colormap (e.g., viridis with a fixed number of colors), the ticks returned by the colorbar’s get_ticks() method do not align with th...
Open Graph Description: Bug summary When creating a colorbar using a ScalarMappable with the NoNorm normalization and a discrete colormap (e.g., viridis with a fixed number of colors), the ticks returned by the colorbar’s...
X Description: Bug summary When creating a colorbar using a ScalarMappable with the NoNorm normalization and a discrete colormap (e.g., viridis with a fixed number of colors), the ticks returned by the colorbar’s...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/31086
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: Colorbar get_ticks() return the incorrect array","articleBody":"### Bug summary\n\nWhen creating a colorbar using a ScalarMappable with the NoNorm normalization and a discrete colormap (e.g., viridis with a fixed number of colors), the ticks returned by the colorbar’s get_ticks() method do not align with the visually displayed tick positions. This will cause `cbar.set_ticks(cbar.get_ticks())` to change the ticks.\n\n### Code for reproduction\n\n```Python\nimport matplotlib.pyplot as plt\nfrom matplotlib import cm, colors\ndata = [1, 2, 3, 4, 5]\nfig, ax = plt.subplots()\ncbar = fig.colorbar(cm.ScalarMappable(norm=colors.NoNorm(), cmap=plt.get_cmap(\"viridis\", len(data))), ax=ax)\nprint(cbar.get_ticks())\ncbar.set_ticks(cbar.get_ticks()) # this unexpectedly changes the ticks\n```\n\n### Actual outcome\n\n[0. 1. 2. 3. 4. 5.]\n\n\u003cimg width=\"510\" height=\"418\" alt=\"Image\" src=\"https://github.com/user-attachments/assets/58104102-4fb1-42f9-8438-2fc5a8bf5c60\" /\u003e\n\n### Expected outcome\n\n[0. 1. 2. 3. 4.]\n\n\u003cimg width=\"510\" height=\"418\" alt=\"Image\" src=\"https://github.com/user-attachments/assets/065c9d5f-1813-46ff-a687-543d7b45d14c\" /\u003e\n\n### Additional information\n\n_No response_\n\n### Operating system\n\n_No response_\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/williamlus","@type":"Person","name":"williamlus"},"datePublished":"2026-02-05T09:44:50.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/31086/matplotlib/issues/31086"}
| 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:10579164-3b25-7f94-43d1-f458dd00d41a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C5AA:177C15:E19E:125E9:6A52BAA6 |
| html-safe-nonce | afe3118777fd38671417786763807445f646f457aa91fdb238118593c55cecac |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNUFBOjE3N0MxNTpFMTlFOjEyNUU5OjZBNTJCQUE2IiwidmlzaXRvcl9pZCI6Ijc3NTE1NDkwMzYyMTAwNzYzMjYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | e1b90feb119ffeccbc76ee0604640ed53f357d772b0a8fad9c57291e35942028 |
| hovercard-subject-tag | issue:3900642742 |
| 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/31086/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7a7adc7c284278960fefca411bbc0e56e00bf23db94e45cbe3978e15c10062d7/matplotlib/matplotlib/issues/31086 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7a7adc7c284278960fefca411bbc0e56e00bf23db94e45cbe3978e15c10062d7/matplotlib/matplotlib/issues/31086 |
| og:image:alt | Bug summary When creating a colorbar using a ScalarMappable with the NoNorm normalization and a discrete colormap (e.g., viridis with a fixed number of colors), the ticks returned by the colorbar’s... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | williamlus |
| 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