Update colorbar with new colorizer API #30008
Open
+101
−49
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
andcolorizer.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:
With the new colorizer API, one would expect be able to replace
cm.ScalarMappable
above withcolorizer.Colorizer
, however, this is currently not possible, and one must instead replacecm.ScalarMappable
above withcolorizer.ColorizingArtist
, which requires acolorizer.Colorizer
as input.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()
withincolorbar.Colorbar()
.This PR updates
colorbar.colorbar()
so that it can accept acolorizer.Colorizer
as an alternative tocolorizer.ColorizingArtist
.The following additional changes are included in this PR:
cm.ScalarMappable
tocolorizer.ColorizingArtist
.colorbar.Colorbar
to the new colorizer API by adding.colorizer
as a mutable property on acolorbar.Colorbar
[this must be mutable as it is mutable forColorizingArtist
and when it changes on the artist it must change on the colorbar].norm
and.cmap
of a colorbar properties that get the relevant property from the colorizer. This also makes the explicitly immutable..mappable
on acolorbar.Colorbar
explicitly immutable.PR checklist
¹ 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.