-
-
Notifications
You must be signed in to change notification settings - Fork 8k
Update Colorizer/ColorizingArtist to work with MultiNorm #30511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
77bc51a
to
9044189
Compare
lib/matplotlib/colorizer.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could probably be simplified by doing something like:
if accept_multivariate:
types = (colors.Colormap, colors.BivarColormap, colors.MultivarColormap)
mappings = (mpl.colormaps, mpl.multivar_colormaps, mpl.bivar_colormaps)
else:
types = (colors.Colormap, )
mappings = (mpl.colormaps, )
and then using those in the checks below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a good idea, now it reads:
if accept_multivariate: types = (colors.Colormap, colors.BivarColormap, colors.MultivarColormap) mappings = (mpl.colormaps, mpl.multivar_colormaps, mpl.bivar_colormaps) else: types = (colors.Colormap, ) mappings = (mpl.colormaps, ) if isinstance(cmap, types): return cmap cmap_name = cmap if cmap is not None else mpl.rcParams["image.cmap"] for mapping in mappings: if cmap_name in mapping: return mapping[cmap_name]
lib/matplotlib/colorizer.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since scalar data gets the braces too, I think you could set n_s = [self.cmap.N]; data = [data]
and use the same os
from the multivariate case for both.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also a good idea, it now reads:
if isinstance(self.norm, colors.MultiNorm): norms = self.norm.norms if isinstance(self.cmap, colors.BivarColormap): n_s = (self.cmap.N, self.cmap.M) else: # colors.MultivarColormap n_s = [part.N for part in self.cmap] else: # colors.Colormap norms = [self.norm] data = [data] n_s = [self.cmap.N] os = [f"{d:-#.{self._sig_digits_from_norm(no, d, n)}g}" for no, d, n in zip(norms, data, n_s)]
Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
9b9aaf3
to
525314e
Compare
Thank you for the feedback @QuLogic and apologies for my sloppy mistakes :)
This PR continues the work of #28658 and #28454, #29876, aiming to close #14168. (Feature request: Bivariate colormapping)
This PR allows Colorizer and ColorizingArtist to work with
MultiNorm
andBivarColormap
andMultivarColormap
i.e. this PR will allow:
Features not included in this PR:
axes.imshow(...)
,axes.pcolor(...), and
axes.pcolormesh(...)`PR checklist