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

Appearance settings

Commit 680f962

Browse filesBrowse files
committed
MultivarColormap and BivarColormap
Creation and tests for classes containing multivariate and bivariate colormaps.
1 parent 0fd212d commit 680f962
Copy full SHA for 680f962

File tree

Expand file treeCollapse file tree

11 files changed

+2609
-7
lines changed
Filter options
Expand file treeCollapse file tree

11 files changed

+2609
-7
lines changed

‎lib/matplotlib/__init__.py

Copy file name to clipboardExpand all lines: lib/matplotlib/__init__.py
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@
129129
"interactive",
130130
"is_interactive",
131131
"colormaps",
132+
"multivar_colormaps",
133+
"bivar_colormaps",
132134
"color_sequences",
133135
]
134136

@@ -1513,4 +1515,6 @@ def inner(ax, *args, data=None, **kwargs):
15131515
# workaround: we must defer colormaps import to after loading rcParams, because
15141516
# colormap creation depends on rcParams
15151517
from matplotlib.cm import _colormaps as colormaps # noqa: E402
1518+
from matplotlib.cm import _multivar_colormaps as multivar_colormaps # noqa: E402
1519+
from matplotlib.cm import _bivar_colormaps as bivar_colormaps # noqa: E402
15161520
from matplotlib.colors import _color_sequences as color_sequences # noqa: E402

‎lib/matplotlib/_cm_bivar.py

Copy file name to clipboardExpand all lines: lib/matplotlib/_cm_bivar.py
+1,312Lines changed: 1312 additions & 0 deletions
Large diffs are not rendered by default.

‎lib/matplotlib/_cm_multivar.py

Copy file name to clipboard
+166Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
# auto-genreated by https://github.com/trygvrad/multivariate_colormaps
2+
# date: 2024-05-28
3+
4+
from .colors import LinearSegmentedColormap, MultivarColormap
5+
import matplotlib as mpl
6+
_LUTSIZE = mpl.rcParams['image.lut']
7+
8+
_2VarAddA0_data = [[0.000, 0.000, 0.000],
9+
[0.020, 0.026, 0.031],
10+
[0.049, 0.068, 0.085],
11+
[0.075, 0.107, 0.135],
12+
[0.097, 0.144, 0.183],
13+
[0.116, 0.178, 0.231],
14+
[0.133, 0.212, 0.279],
15+
[0.148, 0.244, 0.326],
16+
[0.161, 0.276, 0.374],
17+
[0.173, 0.308, 0.422],
18+
[0.182, 0.339, 0.471],
19+
[0.190, 0.370, 0.521],
20+
[0.197, 0.400, 0.572],
21+
[0.201, 0.431, 0.623],
22+
[0.204, 0.461, 0.675],
23+
[0.204, 0.491, 0.728],
24+
[0.202, 0.520, 0.783],
25+
[0.197, 0.549, 0.838],
26+
[0.187, 0.577, 0.895]]
27+
28+
_2VarAddA1_data = [[0.000, 0.000, 0.000],
29+
[0.030, 0.023, 0.018],
30+
[0.079, 0.060, 0.043],
31+
[0.125, 0.093, 0.065],
32+
[0.170, 0.123, 0.083],
33+
[0.213, 0.151, 0.098],
34+
[0.255, 0.177, 0.110],
35+
[0.298, 0.202, 0.120],
36+
[0.341, 0.226, 0.128],
37+
[0.384, 0.249, 0.134],
38+
[0.427, 0.271, 0.138],
39+
[0.472, 0.292, 0.141],
40+
[0.517, 0.313, 0.142],
41+
[0.563, 0.333, 0.141],
42+
[0.610, 0.353, 0.139],
43+
[0.658, 0.372, 0.134],
44+
[0.708, 0.390, 0.127],
45+
[0.759, 0.407, 0.118],
46+
[0.813, 0.423, 0.105]]
47+
48+
_2VarSubA0_data = [[1.000, 1.000, 1.000],
49+
[0.959, 0.973, 0.986],
50+
[0.916, 0.948, 0.974],
51+
[0.874, 0.923, 0.965],
52+
[0.832, 0.899, 0.956],
53+
[0.790, 0.875, 0.948],
54+
[0.748, 0.852, 0.940],
55+
[0.707, 0.829, 0.934],
56+
[0.665, 0.806, 0.927],
57+
[0.624, 0.784, 0.921],
58+
[0.583, 0.762, 0.916],
59+
[0.541, 0.740, 0.910],
60+
[0.500, 0.718, 0.905],
61+
[0.457, 0.697, 0.901],
62+
[0.414, 0.675, 0.896],
63+
[0.369, 0.652, 0.892],
64+
[0.320, 0.629, 0.888],
65+
[0.266, 0.604, 0.884],
66+
[0.199, 0.574, 0.881]]
67+
68+
_2VarSubA1_data = [[1.000, 1.000, 1.000],
69+
[0.982, 0.967, 0.955],
70+
[0.966, 0.935, 0.908],
71+
[0.951, 0.902, 0.860],
72+
[0.937, 0.870, 0.813],
73+
[0.923, 0.838, 0.765],
74+
[0.910, 0.807, 0.718],
75+
[0.898, 0.776, 0.671],
76+
[0.886, 0.745, 0.624],
77+
[0.874, 0.714, 0.577],
78+
[0.862, 0.683, 0.530],
79+
[0.851, 0.653, 0.483],
80+
[0.841, 0.622, 0.435],
81+
[0.831, 0.592, 0.388],
82+
[0.822, 0.561, 0.340],
83+
[0.813, 0.530, 0.290],
84+
[0.806, 0.498, 0.239],
85+
[0.802, 0.464, 0.184],
86+
[0.801, 0.426, 0.119]]
87+
88+
_3VarAddA0_data = [[0.000, 0.000, 0.000],
89+
[0.018, 0.023, 0.028],
90+
[0.040, 0.056, 0.071],
91+
[0.059, 0.087, 0.110],
92+
[0.074, 0.114, 0.147],
93+
[0.086, 0.139, 0.183],
94+
[0.095, 0.163, 0.219],
95+
[0.101, 0.187, 0.255],
96+
[0.105, 0.209, 0.290],
97+
[0.107, 0.230, 0.326],
98+
[0.105, 0.251, 0.362],
99+
[0.101, 0.271, 0.398],
100+
[0.091, 0.291, 0.434],
101+
[0.075, 0.309, 0.471],
102+
[0.046, 0.325, 0.507],
103+
[0.021, 0.341, 0.546],
104+
[0.021, 0.363, 0.584],
105+
[0.022, 0.385, 0.622],
106+
[0.023, 0.408, 0.661]]
107+
108+
_3VarAddA1_data = [[0.000, 0.000, 0.000],
109+
[0.020, 0.024, 0.016],
110+
[0.047, 0.058, 0.034],
111+
[0.072, 0.088, 0.048],
112+
[0.093, 0.116, 0.059],
113+
[0.113, 0.142, 0.067],
114+
[0.131, 0.167, 0.071],
115+
[0.149, 0.190, 0.074],
116+
[0.166, 0.213, 0.074],
117+
[0.182, 0.235, 0.072],
118+
[0.198, 0.256, 0.068],
119+
[0.215, 0.276, 0.061],
120+
[0.232, 0.296, 0.051],
121+
[0.249, 0.314, 0.037],
122+
[0.270, 0.330, 0.018],
123+
[0.288, 0.347, 0.000],
124+
[0.302, 0.369, 0.000],
125+
[0.315, 0.391, 0.000],
126+
[0.328, 0.414, 0.000]]
127+
128+
_3VarAddA2_data = [[0.000, 0.000, 0.000],
129+
[0.029, 0.020, 0.023],
130+
[0.072, 0.045, 0.055],
131+
[0.111, 0.067, 0.084],
132+
[0.148, 0.085, 0.109],
133+
[0.184, 0.101, 0.133],
134+
[0.219, 0.115, 0.155],
135+
[0.254, 0.127, 0.176],
136+
[0.289, 0.138, 0.195],
137+
[0.323, 0.147, 0.214],
138+
[0.358, 0.155, 0.232],
139+
[0.393, 0.161, 0.250],
140+
[0.429, 0.166, 0.267],
141+
[0.467, 0.169, 0.283],
142+
[0.507, 0.168, 0.298],
143+
[0.546, 0.168, 0.313],
144+
[0.580, 0.172, 0.328],
145+
[0.615, 0.175, 0.341],
146+
[0.649, 0.178, 0.355]]
147+
148+
cmaps = {
149+
name: LinearSegmentedColormap.from_list(name, data, _LUTSIZE) for name, data in [
150+
('2VarAddA0', _2VarAddA0_data),
151+
('2VarAddA1', _2VarAddA1_data),
152+
('2VarSubA0', _2VarSubA0_data),
153+
('2VarSubA1', _2VarSubA1_data),
154+
('3VarAddA0', _3VarAddA0_data),
155+
('3VarAddA1', _3VarAddA1_data),
156+
('3VarAddA2', _3VarAddA2_data),
157+
]}
158+
159+
cmap_families = {
160+
'2VarAddA': MultivarColormap('2VarAddA', [cmaps['2VarAddA' + str(i)] for
161+
i in range(2)], 'Add'),
162+
'2VarSubA': MultivarColormap('2VarSubA', [cmaps['2VarSubA' + str(i)] for
163+
i in range(2)], 'Sub'),
164+
'3VarAddA': MultivarColormap('3VarAddA', [cmaps['3VarAddA' + str(i)] for
165+
i in range(3)], 'Add'),
166+
}

‎lib/matplotlib/cm.py

Copy file name to clipboardExpand all lines: lib/matplotlib/cm.py
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
from matplotlib import _api, colors, cbook, scale
2525
from matplotlib._cm import datad
2626
from matplotlib._cm_listed import cmaps as cmaps_listed
27+
from matplotlib._cm_multivar import cmap_families as multivar_cmaps
28+
from matplotlib._cm_bivar import cmaps as bivar_cmaps
2729

2830

2931
_LUTSIZE = mpl.rcParams['image.lut']
@@ -238,6 +240,12 @@ def get_cmap(self, cmap):
238240
_colormaps = ColormapRegistry(_gen_cmap_registry())
239241
globals().update(_colormaps)
240242

243+
_multivar_colormaps = ColormapRegistry(multivar_cmaps)
244+
globals().update(_multivar_colormaps)
245+
246+
_bivar_colormaps = ColormapRegistry(bivar_cmaps)
247+
globals().update(_bivar_colormaps)
248+
241249

242250
# This is an exact copy of pyplot.get_cmap(). It was removed in 3.9, but apparently
243251
# caused more user trouble than expected. Re-added for 3.9.1 and extended the

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.