diff --git a/de_shell/plotting/colormaps.py b/de_shell/plotting/colormaps.py index 9f8966e..80b72d9 100644 --- a/de_shell/plotting/colormaps.py +++ b/de_shell/plotting/colormaps.py @@ -21,7 +21,11 @@ "magma": "magma", "cividis": "cividis", "turbo": "turbo", - "CET_R1": "CET_R1", # diverging + "CET_R1": "CET_R1", # a rainbow, not a diverging map: its middle is yellow + "CET_D1": "CET_D1", # diverging blue-white-red, matplotlib's coolwarm } DEFAULT_COLORMAP = "gray" +#: For a signed map (a strain, a field component): white at the middle, so a +#: range centered on zero shows zero as white. +DIVERGING_COLORMAP = "CET_D1" diff --git a/tests/test_figure.py b/tests/test_figure.py index 449efb3..e09d903 100644 --- a/tests/test_figure.py +++ b/tests/test_figure.py @@ -237,3 +237,27 @@ def test_hiding_the_pill_on_a_closed_figure_is_a_no_op(self): def test_every_figure_frame_relays_its_readout_to_the_host(self): head = fill_iframe_html("").split("")[0] assert "apl:readout" in head and "apl_readout" in head + + +class TestColormaps: + def test_every_name_is_its_own_table(self): + # A misspelled name falls back to the grey ramp without an error, and + # some names are aliases of others; either way the picker would offer + # two entries that draw the same picture. + from anyplotlib._utils import _build_colormap_lut + + from de_shell.plotting.colormaps import COLORMAPS + + tables = {name: bytes(np.asarray(_build_colormap_lut(name), np.uint8)) for name in COLORMAPS} + assert len(set(tables.values())) == len(tables) + + def test_the_diverging_map_is_white_in_the_middle(self): + from anyplotlib._utils import _build_colormap_lut + + from de_shell.plotting.colormaps import COLORMAPS, DIVERGING_COLORMAP + + assert DIVERGING_COLORMAP in COLORMAPS + table = np.asarray(_build_colormap_lut(DIVERGING_COLORMAP), float) + low, middle, high = table[0], table[len(table) // 2], table[-1] + assert middle.min() > 220, "zero should read as white" + assert low[2] > low[0] and high[0] > high[2], "blue below zero, red above" diff --git a/upcoming_changes/20.new_feature.rst b/upcoming_changes/20.new_feature.rst new file mode 100644 index 0000000..d25a911 --- /dev/null +++ b/upcoming_changes/20.new_feature.rst @@ -0,0 +1 @@ +The colormap picker offers ``CET_D1``, a diverging blue-white-red map (matplotlib's ``coolwarm``), and ``DIVERGING_COLORMAP`` names it for signed images. ``CET_R1``, which was listed as the diverging map, is a rainbow.