Skip to content

Commit e42bc53

Browse files
committed
Hard-code under/over values
1 parent 051ab63 commit e42bc53

File tree

1 file changed

+48
-20
lines changed

1 file changed

+48
-20
lines changed

sfs/plot2d.py

Lines changed: 48 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,35 +24,63 @@ def _make_extreme(rgba):
2424
return rgba
2525

2626

27-
def _register_cmap_clip(name, original_name):
28-
"""Create a color map with "over" and "under" values."""
27+
def _register_cmap_with_extremes(name, original_name, **kwargs):
28+
"""Create a color map with "under" and "over" values."""
2929
cmap = _plt.get_cmap(original_name)
30-
cmap = cmap.with_extremes(
31-
under=_make_extreme(cmap.get_under()),
32-
over=_make_extreme(cmap.get_over()))
30+
cmap = cmap.with_extremes(**kwargs)
3331
cmap.name = name
3432
_plt.colormaps.register(cmap=cmap)
3533

3634

37-
_register_cmap_clip('cividis_clip', 'cividis')
38-
_register_cmap_clip('cividis_r_clip', 'cividis_r')
39-
_register_cmap_clip('inferno_clip', 'inferno')
40-
_register_cmap_clip('inferno_r_clip', 'inferno_r')
41-
_register_cmap_clip('magma_clip', 'magma')
42-
_register_cmap_clip('magma_r_clip', 'magma_r')
43-
_register_cmap_clip('plasma_clip', 'plasma')
44-
_register_cmap_clip('plasma_r_clip', 'plasma_r')
45-
_register_cmap_clip('viridis_clip', 'viridis')
46-
_register_cmap_clip('viridis_r_clip', 'viridis_r')
47-
48-
_register_cmap_clip('RdBu_clip', 'RdBu')
49-
_register_cmap_clip('RdBu_r_clip', 'RdBu_r')
35+
# The following under/over values have been calculated with _make_extreme().
36+
# They are hard-coded to avoid a dependency on the library "colorspacious".
37+
_register_cmap_with_extremes('cividis_clip', 'cividis',
38+
under=[0.3581123750444155, 0.4308239004832521, 0.5431626919728758, 1.0],
39+
over=[0.748794386079359, 0.6952014568472878, 0.27380570592765713, 1.0])
40+
_register_cmap_with_extremes('cividis_r_clip', 'cividis_r',
41+
under=[0.748794386079359, 0.6952014568472878, 0.27380570592765713, 1.0],
42+
over=[0.3581123750444155, 0.4308239004832521, 0.5431626919728758, 1.0])
43+
_register_cmap_with_extremes('inferno_clip', 'inferno',
44+
under=[0.3223737972210511, 0.3196564508033573, 0.3474201893768059, 1.0],
45+
over=[0.7759331577663429, 0.7815136432099379, 0.5546145677840046, 1.0])
46+
_register_cmap_with_extremes('inferno_r_clip', 'inferno_r',
47+
under=[0.7759331577663429, 0.7815136432099379, 0.5546145677840046, 1.0],
48+
over=[0.3223737972210511, 0.3196564508033573, 0.3474201893768059, 1.0])
49+
_register_cmap_with_extremes('magma_clip', 'magma',
50+
under=[0.3223737972210511, 0.3196564508033573, 0.3474201893768059, 1.0],
51+
over=[0.7755917106347097, 0.7765145738617047, 0.621366899182334, 1.0])
52+
_register_cmap_with_extremes('magma_r_clip', 'magma_r',
53+
under=[0.7755917106347097, 0.7765145738617047, 0.621366899182334, 1.0],
54+
over=[0.3223737972210511, 0.3196564508033573, 0.3474201893768059, 1.0])
55+
_register_cmap_with_extremes('plasma_clip', 'plasma',
56+
under=[0.3425913695445096, 0.42529714344969144, 0.66039452922638, 1.0],
57+
over=[0.723897190872765, 0.7507494961114689, 0.2574503078804632, 1.0])
58+
_register_cmap_with_extremes('plasma_r_clip', 'plasma_r',
59+
under=[0.723897190872765, 0.7507494961114689, 0.2574503078804632, 1.0],
60+
over=[0.3425913695445096, 0.42529714344969144, 0.66039452922638, 1.0])
61+
_register_cmap_with_extremes('viridis_clip', 'viridis',
62+
under=[0.536623905475994, 0.3775029064902613, 0.5655492658877974, 1.0],
63+
over=[0.7453792828268919, 0.6916769483054797, 0.24219807423955453, 1.0])
64+
_register_cmap_with_extremes('viridis_r_clip', 'viridis_r',
65+
under=[0.7453792828268919, 0.6916769483054797, 0.24219807423955453, 1.0],
66+
over=[0.536623905475994, 0.3775029064902613, 0.5655492658877974, 1.0])
67+
68+
_register_cmap_with_extremes('RdBu_clip', 'RdBu',
69+
under=[0.6931181505544421, 0.3643024937396605, 0.40355267940576434, 1.0],
70+
over=[0.3844199587527661, 0.4705632423745359, 0.597949800233206, 1.0])
71+
_register_cmap_with_extremes('RdBu_r_clip', 'RdBu_r',
72+
under=[0.3844199587527661, 0.4705632423745359, 0.597949800233206, 1.0],
73+
over=[0.6931181505544421, 0.3643024937396605, 0.40355267940576434, 1.0])
5074

5175
# The 'coolwarm' colormap is based on the paper
5276
# "Diverging Color Maps for Scientific Visualization" by Kenneth Moreland
5377
# https://www.kennethmoreland.com/color-maps/ColorMapsExpanded.pdf
54-
_register_cmap_clip('coolwarm_clip', 'coolwarm')
55-
_register_cmap_clip('coolwarm_r_clip', 'coolwarm_r')
78+
_register_cmap_with_extremes('coolwarm_clip', 'coolwarm',
79+
under=[0.510515040101537, 0.5812838578665308, 0.8594377816482693, 1.0],
80+
over=[0.9464304571740522, 0.43619922642510556, 0.4340300540797168, 1.0])
81+
_register_cmap_with_extremes('coolwarm_r_clip', 'coolwarm_r',
82+
under=[0.9464304571740522, 0.43619922642510556, 0.4340300540797168, 1.0],
83+
over=[0.510515040101537, 0.5812838578665308, 0.8594377816482693, 1.0])
5684

5785

5886
def _register_cmap_transparent(name, color):

0 commit comments

Comments
 (0)