Skip to content

Commit 4c18d0c

Browse files
committed
Update plot2d.py
proposed alternative: - instead of having same alpha for both under and over we use individual color weights and alphas for the under/over color - by that the extreme colors can be better adapted towards the individual colormaps, for viridis and cividis to me this is not needed but - inferno, magma, plasma colormaps could then be handled much nicer, if people like to add them one day - the colorwarm URL link did not work, changed to an exisiting one
1 parent f12ff09 commit 4c18d0c

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

sfs/plot2d.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,32 @@
88
from . import util as _util
99

1010

11-
def _register_cmap_clip(name, original_name, alpha):
11+
def _register_cmap_clip(name, original_name, col_alpha_u, col_apha_o):
1212
"""Create a color map with "over" and "under" values."""
1313
cmap = _plt.get_cmap(original_name)
1414
cmap = cmap.with_extremes(
15-
under=cmap.get_under() * [1, 1, 1, alpha],
16-
over=cmap.get_over() * [1, 1, 1, alpha])
15+
under=cmap.get_under() * col_alpha_u,
16+
over=cmap.get_over() * col_apha_o)
1717
cmap.name = name
1818
_plt.colormaps.register(cmap=cmap)
1919

2020

21-
_register_cmap_clip('cividis_clip', 'cividis', 0.6)
22-
_register_cmap_clip('cividis_r_clip', 'cividis_r', 0.6)
23-
_register_cmap_clip('viridis_clip', 'viridis', 0.6)
24-
_register_cmap_clip('viridis_r_clip', 'viridis_r', 0.6)
21+
_register_cmap_clip('cividis_clip', 'cividis',
22+
[1, 1, 1, 0.6],[1, 1, 1, 0.1])
23+
_register_cmap_clip('cividis_r_clip', 'cividis_r',
24+
[1, 1, 1, 0.1], [1, 1, 1, 0.6])
25+
_register_cmap_clip('viridis_clip', 'viridis',
26+
[1, 1, 1, 0.6], [1, 1, 1, 0.1])
27+
_register_cmap_clip('viridis_r_clip', 'viridis_r',
28+
[1, 1, 1, 0.1], [1, 1, 1, 0.6])
2529

2630
# The 'coolwarm' colormap is based on the paper
2731
# "Diverging Color Maps for Scientific Visualization" by Kenneth Moreland
28-
# http://www.sandia.gov/~kmorel/documents/ColorMaps/
29-
_register_cmap_clip('coolwarm_clip', 'coolwarm', 0.6)
30-
_register_cmap_clip('coolwarm_r_clip', 'coolwarm_r', 0.6)
32+
# https://www.kennethmoreland.com/color-maps/ColorMapsExpanded.pdf
33+
_register_cmap_clip('coolwarm_clip', 'coolwarm',
34+
[1, 1, 1, 0.5], [1, 1, 1, 0.5])
35+
_register_cmap_clip('coolwarm_r_clip', 'coolwarm_r',
36+
[1, 1, 1, 0.5], [1, 1, 1, 0.5])
3137

3238

3339
def _register_cmap_transparent(name, color):
@@ -176,7 +182,7 @@ def _visible_secondarysources(x0, n0, grid):
176182
"""Determine secondary sources which lie within *grid*."""
177183
x, y = _util.as_xyz_components(grid[:2])
178184
idx = _np.where((x0[:, 0] > x.min()) & (x0[:, 0] < x.max()) &
179-
(x0[:, 1] > y.min()) & (x0[:, 1] < x.max()))
185+
(x0[:, 1] > y.min()) & (x0[:, 1] < x.max()))
180186
idx = _np.squeeze(idx)
181187

182188
return x0[idx, :], n0[idx, :]

0 commit comments

Comments
 (0)