Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion de_shell/plotting/colormaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
24 changes: 24 additions & 0 deletions tests/test_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("<head></head><body></body>").split("<body>")[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"
1 change: 1 addition & 0 deletions upcoming_changes/20.new_feature.rst
Original file line number Diff line number Diff line change
@@ -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.
Loading