allow setting colormap

This commit is contained in:
2021-06-09 13:33:06 +02:00
parent 3e34de69d5
commit c2c4c6ab58
3 changed files with 28 additions and 4 deletions

View File

@ -1,7 +1,7 @@
from .frame import Frame
from .logic import decide_src_plt_cfg
from .cfgdlgs import ConfigDialog1D #TODO
from .cfgdlgs import ConfigDialog1D, ConfigDialog2D #TODO
class Actor:
@ -29,6 +29,11 @@ class Actor:
cfg.error_bands.on_click(plt.show_error_bands)
cfg.error_bars.on_click(plt.show_error_bars)
if isinstance(cfg, ConfigDialog2D): #TODO
cfg.sel_cmap.value = plt.palette
cfg.sel_cmap.on_change("value", lambda _attr, _old, new: plt.change_cmap(new))
def delete(self):
self.cache = None

View File

@ -1,14 +1,26 @@
from bokeh.models import TextInput
from bokeh.models import Select, TextInput
from ..buki import Column
CMAPS = [
"Plasma",
"Turbo",
"Viridis"
]
class ConfigDialog2D(Column):
def __init__(self):
self.ti_cache_size = ti_cache_size = TextInput(value="", title="Cache size:")
ti_cache_size.disabled = True # 2D plot only shows the latest image
super().__init__(ti_cache_size)
self.sel_cmap = sel_cmap = Select(title="Colormap", options=CMAPS)
super().__init__(ti_cache_size, sel_cmap)
#TODO: vmin, vmax, binning, log

View File

@ -2,6 +2,7 @@ import numpy as np
from bokeh.plotting import figure
from bokeh.models import ColumnDataSource, ColorBar, LinearColorMapper
from bokeh.palettes import all_palettes
from ..buki import Object
@ -15,7 +16,8 @@ class Plot2D(Object):
self.source = source = ColumnDataSource(data=data)
cmap = LinearColorMapper(palette="Viridis256")
self.cmap = cmap = LinearColorMapper()
self.change_cmap("Viridis")
cbar = ColorBar(color_mapper=cmap)
fig = figure(name=name, match_aspect=True)
@ -33,4 +35,9 @@ class Plot2D(Object):
self.source.data.update(image=[image])
def change_cmap(self, name):
self.palette = name
self.cmap.palette = all_palettes[name][256]