Title: Update colorbar with new colorizer API by trygvrad · Pull Request #30008 · matplotlib/matplotlib · GitHub
Open Graph Title: Update colorbar with new colorizer API by trygvrad · Pull Request #30008 · matplotlib/matplotlib
X Title: Update colorbar with new colorizer API by trygvrad · Pull Request #30008 · matplotlib/matplotlib
Description: Updates colorbar.colorbar to accept a colorizer.Colorizer object, in addition to colorizer.ColorizingArtist. This commit also changes the docs from referencing cm.ScalarMappable to referencing colorizer.ColorizingArtist. PR summary With the introduction of colorizer.Colorizer and colorizer.ColorizingArtist (#28658) we have separated the norm→color pipeline from the artist. However, the colorbar API has not been updated since these changes took effect. Consider this example: fig, ax = plt.subplots(figsize=(6, 1), layout='constrained') norm = mpl.colors.Normalize(vmin=5, vmax=10) fig.colorbar(mpl.cm.ScalarMappable(norm=norm, cmap='cool'), cax=ax, orientation='horizontal', label='Some Units') With the new colorizer API, one would expect be able to replace cm.ScalarMappable above with colorizer.Colorizer, however, this is currently not possible, and one must instead replace cm.ScalarMappable above with colorizer.ColorizingArtist, which requires a colorizer.Colorizer as input. fig.colorbar(mpl.colorizer.ColorizingArtist(mpl.colorizer.Colorizer(norm=norm, cmap='cool')), cax=ax, orientation='horizontal', label='Some Units') This is despite the fact that the norm→color pipeline is entirely contained in the colorizer, and it fails only because of a single call to self.mappable.get_array() within colorbar.Colorbar(). This PR updates colorbar.colorbar() so that it can accept a colorizer.Colorizer as an alternative to colorizer.ColorizingArtist. fig.colorbar(mpl.colorizer.Colorizer(norm=norm, cmap='cool'), cax=ax, orientation='horizontal', label='Some Units') The following additional changes are included in this PR: Changes the docs from referencing cm.ScalarMappable to colorizer.ColorizingArtist. Updates colorbar.Colorbar to the new colorizer API by adding .colorizer as a mutable property on a colorbar.Colorbar [this must be mutable as it is mutable for ColorizingArtist and when it changes on the artist it must change on the colorbar] makes the .norm and .cmap of a colorbar properties that get the relevant property from the colorizer. This also makes the explicitly immutable. makes the .mappable on a colorbar.Colorbar explicitly immutable. PR checklist new and changed code is tested [¹] Plotting related features are demonstrated in an example New Features and API Changes are noted with a directive and release note Documentation complies with general and docstring guidelines ¹ I would like to update https://matplotlib.org/stable/users/explain/colors/colorbar_only.html and https://matplotlib.org/stable/gallery/images_contours_and_fields/multi_image.html but I think that would benefit from having this PR be implemented first.
Open Graph Description: Updates colorbar.colorbar to accept a colorizer.Colorizer object, in addition to colorizer.ColorizingArtist. This commit also changes the docs from referencing cm.ScalarMappable to referencing colo...
X Description: Updates colorbar.colorbar to accept a colorizer.Colorizer object, in addition to colorizer.ColorizingArtist. This commit also changes the docs from referencing cm.ScalarMappable to referencing colo...
Opengraph URL: https://github.com/matplotlib/matplotlib/pull/30008
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:4ab4cedf-bfaa-ca70-90e8-045a24331a5d |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | C6E6:20B94F:A740BE:DF8EA9:6A51A8D9 |
| html-safe-nonce | e931d6c7aa2e532b544bc84de9c662e2522c5277e01c54ac6598d8178d2ce1fb |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNkU2OjIwQjk0RjpBNzQwQkU6REY4RUE5OjZBNTFBOEQ5IiwidmlzaXRvcl9pZCI6IjgyOTI4MjE0ODU0MDMyODE1MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | a8ca978b3a04e7b2abf4a7ad4073ad66dee7db68ae88a038e791ab2f65985caf |
| hovercard-subject-tag | pull_request:2497291506 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,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/matplotlib/matplotlib/pull/30008/files |
| twitter:image | https://avatars.githubusercontent.com/u/2361452?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/2361452?s=400&v=4 |
| og:image:alt | Updates colorbar.colorbar to accept a colorizer.Colorizer object, in addition to colorizer.ColorizingArtist. This commit also changes the docs from referencing cm.ScalarMappable to referencing colo... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| diff-view | unified |
| 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 full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7aed05249554b889eb33d002851a973eebcc7e91 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width