GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — MultivarColormap and BivarColormap by trygvrad · Pull Request #28454 · matplotlib/matplotlib

MultivarColormap and BivarColormap #28454

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.

Sign up for GitHub

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

Merged
story645 merged 18 commits into matplotlib:main from trygvrad:Multivariate-colormap-types
Aug 23, 2024

Uh oh!

There was an error while loading. Please reload this page.

Merged

MultivarColormap and BivarColormap #28454

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
c803091
MultivarColormap and BivarColormap
trygvrad Jun 25, 2024
f09791c
__getitem__ for colors.BivarColormap
trygvrad Jul 2, 2024
8c848aa
Better descriptors for 'Add' and 'Sub' in colors.MultivarColormap
trygvrad Jul 2, 2024
2213a88
minor fixes for MultivarColormap and BivarColormap
trygvrad Jul 3, 2024
446e1bd
Allows one to not clip to 0...1 in colors.MultivarColormap.__call__()
trygvrad Jul 3, 2024
04228c7
Multivariate and bivariate resampling of colormaps
trygvrad Jul 5, 2024
2911933
Corrected stubs for mutlivariate and bivariate colormaps
trygvrad Jul 6, 2024
e7d884c
minor fixes to colors.py
trygvrad Jul 9, 2024
d365483
Rename 'Add' to 'sRGB_add'
trygvrad Jul 18, 2024
77da937
name as keyword variable and additional tests to multivariate colormaps
trygvrad Jul 25, 2024
e688f03
Apply suggestions from code review
trygvrad Aug 5, 2024
69f9977
Fixes based on feedback on review
trygvrad Aug 5, 2024
8e3f393
removed exposure of multivariate and bivariate colormaps in cm.globals()
trygvrad Aug 7, 2024
a35bc29
improved docstring for MultivarColormap
trygvrad Aug 12, 2024
b73adcf
Apply suggestions from code review
trygvrad Aug 19, 2024
438923f
test _repr_png_() for MultivarColormap
trygvrad Aug 19, 2024
dcf6f8a
improved docstring for SegmentedBivarColormap()
trygvrad Aug 19, 2024
f2f2d71
updated default arguments in docs for multivar and bivar colormaps
trygvrad Aug 22, 2024
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

4 changes: 4 additions & 0 deletions 4 lib/matplotlib/__init__.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@
"interactive",
"is_interactive",
"colormaps",
"multivar_colormaps",
"bivar_colormaps",
"color_sequences",
]

Expand Down Expand Up @@ -1543,4 +1545,6 @@ def validate_backend(s):
# workaround: we must defer colormaps import to after loading rcParams, because
# colormap creation depends on rcParams
from matplotlib.cm import _colormaps as colormaps # noqa: E402
from matplotlib.cm import _multivar_colormaps as multivar_colormaps # noqa: E402
from matplotlib.cm import _bivar_colormaps as bivar_colormaps # noqa: E402
from matplotlib.colors import _color_sequences as color_sequences # noqa: E402
2 changes: 2 additions & 0 deletions 2 lib/matplotlib/__init__.pyi
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,6 @@ def _preprocess_data(
) -> Callable: ...

from matplotlib.cm import _colormaps as colormaps # noqa: E402
from matplotlib.cm import _multivar_colormaps as multivar_colormaps # noqa: E402
from matplotlib.cm import _bivar_colormaps as bivar_colormaps # noqa: E402
from matplotlib.colors import _color_sequences as color_sequences # noqa: E402
1,312 changes: 1,312 additions & 0 deletions 1,312 lib/matplotlib/_cm_bivar.py
Show comments
View file
Open in desktop

Large diffs are not rendered by default.

Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

166 changes: 166 additions & 0 deletions 166 lib/matplotlib/_cm_multivar.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
# auto-generated by https://github.com/trygvrad/multivariate_colormaps
# date: 2024-05-28

from .colors import LinearSegmentedColormap, MultivarColormap
import matplotlib as mpl
_LUTSIZE = mpl.rcParams['image.lut']

_2VarAddA0_data = [[0.000, 0.000, 0.000],
[0.020, 0.026, 0.031],
[0.049, 0.068, 0.085],
[0.075, 0.107, 0.135],
[0.097, 0.144, 0.183],
[0.116, 0.178, 0.231],
[0.133, 0.212, 0.279],
[0.148, 0.244, 0.326],
[0.161, 0.276, 0.374],
[0.173, 0.308, 0.422],
[0.182, 0.339, 0.471],
[0.190, 0.370, 0.521],
[0.197, 0.400, 0.572],
[0.201, 0.431, 0.623],
[0.204, 0.461, 0.675],
[0.204, 0.491, 0.728],
[0.202, 0.520, 0.783],
[0.197, 0.549, 0.838],
[0.187, 0.577, 0.895]]

_2VarAddA1_data = [[0.000, 0.000, 0.000],
[0.030, 0.023, 0.018],
[0.079, 0.060, 0.043],
[0.125, 0.093, 0.065],
[0.170, 0.123, 0.083],
[0.213, 0.151, 0.098],
[0.255, 0.177, 0.110],
[0.298, 0.202, 0.120],
[0.341, 0.226, 0.128],
[0.384, 0.249, 0.134],
[0.427, 0.271, 0.138],
[0.472, 0.292, 0.141],
[0.517, 0.313, 0.142],
[0.563, 0.333, 0.141],
[0.610, 0.353, 0.139],
[0.658, 0.372, 0.134],
[0.708, 0.390, 0.127],
[0.759, 0.407, 0.118],
[0.813, 0.423, 0.105]]

_2VarSubA0_data = [[1.000, 1.000, 1.000],
[0.959, 0.973, 0.986],
[0.916, 0.948, 0.974],
[0.874, 0.923, 0.965],
[0.832, 0.899, 0.956],
[0.790, 0.875, 0.948],
[0.748, 0.852, 0.940],
[0.707, 0.829, 0.934],
[0.665, 0.806, 0.927],
[0.624, 0.784, 0.921],
[0.583, 0.762, 0.916],
[0.541, 0.740, 0.910],
[0.500, 0.718, 0.905],
[0.457, 0.697, 0.901],
[0.414, 0.675, 0.896],
[0.369, 0.652, 0.892],
[0.320, 0.629, 0.888],
[0.266, 0.604, 0.884],
[0.199, 0.574, 0.881]]

_2VarSubA1_data = [[1.000, 1.000, 1.000],
[0.982, 0.967, 0.955],
[0.966, 0.935, 0.908],
[0.951, 0.902, 0.860],
[0.937, 0.870, 0.813],
[0.923, 0.838, 0.765],
[0.910, 0.807, 0.718],
[0.898, 0.776, 0.671],
[0.886, 0.745, 0.624],
[0.874, 0.714, 0.577],
[0.862, 0.683, 0.530],
[0.851, 0.653, 0.483],
[0.841, 0.622, 0.435],
[0.831, 0.592, 0.388],
[0.822, 0.561, 0.340],
[0.813, 0.530, 0.290],
[0.806, 0.498, 0.239],
[0.802, 0.464, 0.184],
[0.801, 0.426, 0.119]]

_3VarAddA0_data = [[0.000, 0.000, 0.000],
[0.018, 0.023, 0.028],
[0.040, 0.056, 0.071],
[0.059, 0.087, 0.110],
[0.074, 0.114, 0.147],
[0.086, 0.139, 0.183],
[0.095, 0.163, 0.219],
[0.101, 0.187, 0.255],
[0.105, 0.209, 0.290],
[0.107, 0.230, 0.326],
[0.105, 0.251, 0.362],
[0.101, 0.271, 0.398],
[0.091, 0.291, 0.434],
[0.075, 0.309, 0.471],
[0.046, 0.325, 0.507],
[0.021, 0.341, 0.546],
[0.021, 0.363, 0.584],
[0.022, 0.385, 0.622],
[0.023, 0.408, 0.661]]

_3VarAddA1_data = [[0.000, 0.000, 0.000],
[0.020, 0.024, 0.016],
[0.047, 0.058, 0.034],
[0.072, 0.088, 0.048],
[0.093, 0.116, 0.059],
[0.113, 0.142, 0.067],
[0.131, 0.167, 0.071],
[0.149, 0.190, 0.074],
[0.166, 0.213, 0.074],
[0.182, 0.235, 0.072],
[0.198, 0.256, 0.068],
[0.215, 0.276, 0.061],
[0.232, 0.296, 0.051],
[0.249, 0.314, 0.037],
[0.270, 0.330, 0.018],
[0.288, 0.347, 0.000],
[0.302, 0.369, 0.000],
[0.315, 0.391, 0.000],
[0.328, 0.414, 0.000]]

_3VarAddA2_data = [[0.000, 0.000, 0.000],
[0.029, 0.020, 0.023],
[0.072, 0.045, 0.055],
[0.111, 0.067, 0.084],
[0.148, 0.085, 0.109],
[0.184, 0.101, 0.133],
[0.219, 0.115, 0.155],
[0.254, 0.127, 0.176],
[0.289, 0.138, 0.195],
[0.323, 0.147, 0.214],
[0.358, 0.155, 0.232],
[0.393, 0.161, 0.250],
[0.429, 0.166, 0.267],
[0.467, 0.169, 0.283],
[0.507, 0.168, 0.298],
[0.546, 0.168, 0.313],
[0.580, 0.172, 0.328],
[0.615, 0.175, 0.341],
[0.649, 0.178, 0.355]]

cmaps = {
name: LinearSegmentedColormap.from_list(name, data, _LUTSIZE) for name, data in [
('2VarAddA0', _2VarAddA0_data),
Comment thread

@QuLogic QuLogic Jul 31, 2024

Copy link
Copy Markdown
Member

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.

These are pretty esoteric names; are they documented somewhere? Might even need a comment here as well.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@trygvrad trygvrad Aug 1, 2024

Copy link
Copy Markdown
Contributor Author

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.

@QuLogic thanks for all the comments
These are placeholders so that we have something to test with for this PR.
We should have a longer discussion about them in a later PR, which will also introduce more of them.
see this comment for a rough timeline #28428 (comment)
(I have been thinking we need sets from 2-8 colors)
At that point we should decide on a naming scheme.

I wrote a blogpost about their design here: https://trygvrad.github.io/multivariate-colormaps-for-n-dimensions/

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@story645 story645 Aug 1, 2024

Copy link
Copy Markdown
Member

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.

So one of the reasons I suggested we maybe pull these in as dark mode cmaps #28454 (comment), and I'm okay w/ that happening in a later PR, is that we could then probably have more semantically meaningful names based on the individual maps.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
('2VarAddA1', _2VarAddA1_data),
('2VarSubA0', _2VarSubA0_data),
('2VarSubA1', _2VarSubA1_data),
('3VarAddA0', _3VarAddA0_data),
('3VarAddA1', _3VarAddA1_data),
('3VarAddA2', _3VarAddA2_data),
]}

cmap_families = {
'2VarAddA': MultivarColormap([cmaps[f'2VarAddA{i}'] for i in range(2)],
'sRGB_add', name='2VarAddA'),
'2VarSubA': MultivarColormap([cmaps[f'2VarSubA{i}'] for i in range(2)],
'sRGB_sub', name='2VarSubA'),
'3VarAddA': MultivarColormap([cmaps[f'3VarAddA{i}'] for i in range(3)],
'sRGB_add', name='3VarAddA'),
}
6 changes: 6 additions & 0 deletions 6 lib/matplotlib/cm.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
from matplotlib import _api, colors, cbook, scale
from matplotlib._cm import datad
from matplotlib._cm_listed import cmaps as cmaps_listed
from matplotlib._cm_multivar import cmap_families as multivar_cmaps
from matplotlib._cm_bivar import cmaps as bivar_cmaps


_LUTSIZE = mpl.rcParams['image.lut']
Expand Down Expand Up @@ -238,6 +240,10 @@ def get_cmap(self, cmap):
_colormaps = ColormapRegistry(_gen_cmap_registry())
globals().update(_colormaps)

_multivar_colormaps = ColormapRegistry(multivar_cmaps)

_bivar_colormaps = ColormapRegistry(bivar_cmaps)


# This is an exact copy of pyplot.get_cmap(). It was removed in 3.9, but apparently
# caused more user trouble than expected. Re-added for 3.9.1 and extended the
Expand Down
2 changes: 2 additions & 0 deletions 2 lib/matplotlib/cm.pyi
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class ColormapRegistry(Mapping[str, colors.Colormap]):
def get_cmap(self, cmap: str | colors.Colormap) -> colors.Colormap: ...

_colormaps: ColormapRegistry = ...
_multivar_colormaps: ColormapRegistry = ...
_bivar_colormaps: ColormapRegistry = ...

def get_cmap(name: str | colors.Colormap | None = ..., lut: int | None = ...) -> colors.Colormap: ...

Expand Down
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.