Skip to content

Update Colorizer/ColorizingArtist to work with MultiNorm#30511

Merged
story645 merged 4 commits intomatplotlib:mainfrom
trygvrad:colorizer-multinorm
Oct 30, 2025
Merged

Update Colorizer/ColorizingArtist to work with MultiNorm#30511
story645 merged 4 commits intomatplotlib:mainfrom
trygvrad:colorizer-multinorm

Conversation

@trygvrad
Copy link
Copy Markdown
Contributor

@trygvrad trygvrad commented Sep 3, 2025

EDIT: closes #30511

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

Comment thread lib/matplotlib/cbook.py Outdated
Comment thread lib/matplotlib/colorizer.py Outdated
Comment thread lib/matplotlib/colorizer.py Outdated
Comment thread lib/matplotlib/colorizer.py Outdated
Comment thread lib/matplotlib/tests/test_colors.py Outdated
Comment thread lib/matplotlib/colorizer.py Outdated
Comment thread lib/matplotlib/colorizer.py Outdated
Comment thread lib/matplotlib/colorizer.py Outdated
Comment thread lib/matplotlib/colorizer.py Outdated
Comment thread lib/matplotlib/colorizer.py Outdated
@trygvrad
Copy link
Copy Markdown
Contributor Author

trygvrad commented Sep 4, 2025

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

improved testing for colorizer+multinorm

Apply suggestions from code review

Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>

updates based on feedback from @QuLogic
Comment thread lib/matplotlib/colorizer.py Outdated
Comment thread lib/matplotlib/colorizer.py Outdated
Comment thread lib/matplotlib/tests/test_colors.py Outdated
Comment thread lib/matplotlib/colorizer.py Outdated
Comment thread lib/matplotlib/colorizer.py Outdated
Copy link
Copy Markdown
Member

@QuLogic QuLogic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I mentioned on the call, I think this looks okay from a low-level point-of-view, but I am at this point uncertain as to the high-level status. I hope someone more familiar with the current state can confirm.

PS, @trygvrad if you have some time to pop in to the call, it would be good to just re-iterate the current state succinctly, as I'm not sure everyone is up-to-speed right now.

@trygvrad trygvrad mentioned this pull request Sep 24, 2025
2 tasks
Copy link
Copy Markdown
Member

@story645 story645 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry it took so long to get to this.

Comment thread lib/matplotlib/colorizer.py Outdated
if norm and (xx.max() > 1 or xx.min() < 0):
raise ValueError("Floating point image RGB values "
"must be in the 0..1 range.")
"must be in the 0..1 range")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"must be in the 0..1 range")
"must be in the [0,1] range")

teenyist nit but I find interval notation clearer

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: This required a change to an existing test test_colors.py→test_scalarmappable_nan_to_rgba(bytes) which had a regex for the string '0..1 range'

Comment thread lib/matplotlib/colorizer.py Outdated
Comment thread lib/matplotlib/colorizer.py
Comment thread lib/matplotlib/colorizer.py
Comment thread lib/matplotlib/colorizer.py Outdated
Comment on lines +899 to +902
elif n_components == 2:
raise ValueError("Invalid data entry for multivariate data. The data"
" must contain complex numbers, or have a first dimension 2,"
" or be of a dtype with 2 fields")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not following what 2 components means in this context

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We had a discussion when declaring MultiNorm that we should refer to the different channels/variates as components, so MultiNorm has the property n_components which is the number of channels/variates/components.

In the following example it would be 2, because the colormap supports 2 channels, and we provide 2 datasets.

plt.imshow((A, B), cmap='BiOrangeBlue')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Sorry for forgetting this. :/

@trygvrad
Copy link
Copy Markdown
Contributor Author

Sorry it took so long to get to this.

No worries, thank you for getting around to it :)

Co-authored-by: hannah <story645@gmail.com>
@trygvrad trygvrad force-pushed the colorizer-multinorm branch from cf9296d to 9409d4c Compare October 11, 2025 18:42
Copy link
Copy Markdown
Member

@story645 story645 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments but definitely not blocking, will leave unmerged for a day but they can also be addressed on followup. Thanks for all your patience and persistence.

Comment thread lib/matplotlib/colorizer.py Outdated
Comment on lines +899 to +902
elif n_components == 2:
raise ValueError("Invalid data entry for multivariate data. The data"
" must contain complex numbers, or have a first dimension 2,"
" or be of a dtype with 2 fields")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Sorry for forgetting this. :/

@trygvrad
Copy link
Copy Markdown
Contributor Author

@story645 I added the test we discussed, please take a look at the last commit :)

Comment thread lib/matplotlib/colorizer.py Outdated
@trygvrad trygvrad force-pushed the colorizer-multinorm branch from 8745b81 to 6934853 Compare October 29, 2025 20:41
@story645 story645 added this to the v3.11.0 milestone Oct 30, 2025
@story645 story645 merged commit 78617c1 into matplotlib:main Oct 30, 2025
35 of 39 checks passed
@story645
Copy link
Copy Markdown
Member

doc build failures seem to be intersphinx related

andreas16700 added a commit to andreas16700/matplotlib that referenced this pull request Jan 28, 2026
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

Feature request: Bivariate colormapping

3 participants