Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Open
trygvrad wants to merge 4 commits into matplotlib:main
base: main
Choose a base branch
Loading
from trygvrad:colorizer-multinorm

Conversation

Copy link
Contributor

@trygvrad trygvrad commented Sep 3, 2025

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 and BivarColormap and MultivarColormap

i.e. this PR will allow:

import matplotlib.pyplot as plt
import numpy as np
import matplotlib as mpl
a = np.arange(12).reshape(3,4)
b = np.arange(12).reshape(4,3).T
norm = mpl.colors.Normalize(vmin=0, vmax=11)
col = mpl.colorizer.Colorizer(cmap='BiOrangeBlue', norm=[norm, norm])
plt.imshow(col.to_rgba((a, b)))
image

Features not included in this PR:

  • Exposes the functionality provided by MultiNorm together with BivarColormap and MultivarColormap to the plotting functions axes.imshow(...), axes.pcolor(...), and axes.pcolormesh(...)`
  • fig.colorbar() equivalents for BivarColormap and MultivarColormap
  • Examples in the docs

PR checklist

  • new and changed code is tested

Colormap

"""
if not accept_multivariate:
Copy link
Member

@QuLogic QuLogic Sep 4, 2025

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.

Copy link
Contributor Author

@trygvrad trygvrad Sep 4, 2025

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]

# scalar data
n = self.cmap.N
g_sig_digits = self._sig_digits_from_norm(self.norm, data, n)
return f"[{data:-#.{g_sig_digits}g}]"
Copy link
Member

@QuLogic QuLogic Sep 4, 2025

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.

Copy link
Contributor Author

@trygvrad trygvrad Sep 4, 2025

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)]

trygvrad and others added 2 commits September 4, 2025 23:45
Copy link
Contributor Author

trygvrad commented Sep 4, 2025

Thank you for the feedback @QuLogic and apologies for my sloppy mistakes :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@QuLogic QuLogic QuLogic left review comments

At least 1 approving review is required to merge this pull request.

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Feature request: Bivariate colormapping
2 participants

AltStyle によって変換されたページ (->オリジナル) /