added checkbox to reverse colormap

This commit is contained in:
2021-06-10 10:39:20 +02:00
parent acb3f06682
commit 59888c07d4
3 changed files with 27 additions and 8 deletions

View File

@ -31,10 +31,14 @@ class Actor:
cfg.error_bars.on_click(plt.show_error_bars)
if isinstance(cfg, ConfigDialog2D): #TODO
cfg.sel_cmap.value = plt.palette
cfg.sel_cmap_palette.value = plt.cmap_palette
cfg.cb_cmap_reverse.active = plt.cmap_reverse
cfg.sp_binning.value = plt.binning
cfg.sel_cmap.on_change("value", cb(plt.change_cmap))
cfg.sel_cmap_palette.on_change("value", cb(plt.change_cmap_palette))
cfg.cb_cmap_reverse.on_click(plt.change_cmap_reverse)
cfg.sp_vmin.on_change("value", cb(plt.change_vmin))
cfg.sp_vmax.on_change("value", cb(plt.change_vmax))
cfg.sp_binning.on_change("value", cb(plt.change_binning))

View File

@ -1,6 +1,7 @@
from bokeh.models import Select, Spinner
from ..buki import Column, Row
from ..widgets import Checkbox
CMAPS = [
@ -15,13 +16,15 @@ class ConfigDialog2D(Column):
def __init__(self):
self.sp_cache_size = sp_cache_size = Spinner(title="Cache size:")
sp_cache_size.disabled = True # 2D plot only shows the latest image
self.sel_cmap = sel_cmap = Select(title="Colormap", options=CMAPS)
self.sel_cmap_palette = sel_cmap_palette = Select(title="Colormap", options=CMAPS)
self.cb_cmap_reverse = cb_cmap_reverse = Checkbox(label="Reverse Colormap")
self.sp_vmin = sp_vmin = Spinner(title="Minimum Value")
self.sp_vmax = sp_vmax = Spinner(title="Maximum Value")
self.sp_binning = sp_binning = Spinner(title="Binning", low=1)
super().__init__(
sp_cache_size,
sel_cmap,
sel_cmap_palette,
cb_cmap_reverse,
Row(sp_vmin, sp_vmax),
sp_binning
)

View File

@ -19,7 +19,9 @@ class Plot2D(Object):
self.binning = 1
self.cmap = cmap = LinearColorMapper()
self.change_cmap("Viridis")
self.cmap_palette = "Viridis"
self.cmap_reverse = False
self._update_cmap()
cbar = ColorBar(color_mapper=cmap)
fig = figure(name=name, match_aspect=True)
@ -38,9 +40,19 @@ class Plot2D(Object):
self.source.data.update(image=[image])
def change_cmap(self, name):
self.palette = name
self.cmap.palette = all_palettes[name][256]
def change_cmap_palette(self, name):
self.cmap_palette = name
self._update_cmap()
def change_cmap_reverse(self, state):
self.cmap_reverse = state
self._update_cmap()
def _update_cmap(self):
pal = all_palettes[self.cmap_palette][256]
if self.cmap_reverse:
pal = pal[::-1]
self.cmap.palette = pal
def change_vmin(self, value):
self.cmap.low = value