Title: [Bug]: Image color limits not correctly updated with set_clim() IFF color bar present AND new norm.vmin > old norm.vmax · Issue #29522 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: Image color limits not correctly updated with set_clim() IFF color bar present AND new norm.vmin > old norm.vmax · Issue #29522 · matplotlib/matplotlib
X Title: [Bug]: Image color limits not correctly updated with set_clim() IFF color bar present AND new norm.vmin > old norm.vmax · Issue #29522 · matplotlib/matplotlib
Description: Bug summary I experienced some specific odd cases where I noticed that the colors of an image were not correctly set after updating the image data and setting new color limits with set_clim(). After debugging I was able to reproduce with...
Open Graph Description: Bug summary I experienced some specific odd cases where I noticed that the colors of an image were not correctly set after updating the image data and setting new color limits with set_clim(). Afte...
X Description: Bug summary I experienced some specific odd cases where I noticed that the colors of an image were not correctly set after updating the image data and setting new color limits with set_clim(). Afte...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/29522
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: Image color limits not correctly updated with set_clim() IFF color bar present AND new norm.vmin \u003e old norm.vmax","articleBody":"### Bug summary\n\nI experienced some specific odd cases where I noticed that the colors of an image were not correctly set after updating the image data and setting new color limits with set_clim(). After debugging I was able to reproduce with a minimal example,..\n\n\n### Code for reproduction\n\n```Python\nimport numpy as np\nfrom matplotlib import pyplot as plt\n\n\n# Create test data\nnp.random.seed(19771105)\ndata_0 = np.round(np.random.rand(10, 20), 1)\ndata_1 = data_0 + 10\n\n# Compute data range\nrange_0 = data_0.min(), data_0.max()\nrange_1 = data_1.min(), data_1.max()\n\n# Plot data as image; Auto adjusts colorbar scale to value range\nimage = plt.imshow(data_0)\ncbar = plt.colorbar(image) # NOTE: Problem does not occur if colorbar not created!\n\nprint(f'expected norm = {range_0}')\nprint(f'actual norm = {image.norm.vmin, image.norm.vmax}')\n\n# Change image data and update image color limits\nimage.set_data(data_1)\nimage.set_clim(range_1)\n\nprint(f'expected norm = {range_1}')\nprint(f'actual norm = {image.norm.vmin, image.norm.vmax}') # Incorrect!\n\nplt.show()\n```\n\n### Actual outcome\n\n```\nexpected initial norm = (0.0, 1.0)\ncomputed initial norm = (0.0, 1.0)\nexpected updated norm = (10.0, 11.0)\ncomputed updated norm = (0.9, 11.0)\n```\n\n\n\n### Expected outcome\n\n```\nexpected initial norm = (0.0, 1.0)\ncomputed initial norm = (0.0, 1.0)\nexpected updated norm = (10.0, 11.0)\ncomputed updated norm = (10.0, 11.0)\n```\n\n\n\n### Additional information\n\nOnly happens if color bar is present; Removing the line that creates it from code lets you see the correct image (minus color bar).\nData dependent; Only occurs if the lowest value of the new image data is higher than the highest value of the old image data (Hence +10 in the code example).\n\n\n### Operating system\n\nWindows 10\n\n### Matplotlib Version\n\n\u003e3.6.0\n\n### Matplotlib Backend\n\nQtAgg\n\n### Python version\n\n3.11.9\n\n### Jupyter version\n\n-\n\n### Installation\n\npip","author":{"url":"https://github.com/erikdendekker","@type":"Person","name":"erikdendekker"},"datePublished":"2025-01-25T21:46:43.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":15},"url":"https://github.com/29522/matplotlib/issues/29522"}
| 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:81b721a1-9ea9-72c7-391e-84b832d68944 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 93B6:1661F0:5C07D8:7B7AD5:6A5268A0 |
| html-safe-nonce | c017f9e8a69aeb64f7e9637a894e6e16b87d13ac76fa669c653ab5e430cbe6d6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5M0I2OjE2NjFGMDo1QzA3RDg6N0I3QUQ1OjZBNTI2OEEwIiwidmlzaXRvcl9pZCI6IjQzMDc2NDAwODg0MTY5MDUzNzYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | a705e499d9b3bdb203efda2bc48bb50d7d003e883f9dab2441d73435906a2cfc |
| hovercard-subject-tag | issue:2811190405 |
| 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/29522/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e32330f9afeebf5915900537b2a75c9b68e5206ff3e4af425d49f352da5286da/matplotlib/matplotlib/issues/29522 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e32330f9afeebf5915900537b2a75c9b68e5206ff3e4af425d49f352da5286da/matplotlib/matplotlib/issues/29522 |
| og:image:alt | Bug summary I experienced some specific odd cases where I noticed that the colors of an image were not correctly set after updating the image data and setting new color limits with set_clim(). Afte... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | erikdendekker |
| 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 | canary-1 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width