allow setting colormap
This commit is contained in:
@ -1,7 +1,7 @@
|
|||||||
from .frame import Frame
|
from .frame import Frame
|
||||||
from .logic import decide_src_plt_cfg
|
from .logic import decide_src_plt_cfg
|
||||||
|
|
||||||
from .cfgdlgs import ConfigDialog1D #TODO
|
from .cfgdlgs import ConfigDialog1D, ConfigDialog2D #TODO
|
||||||
|
|
||||||
|
|
||||||
class Actor:
|
class Actor:
|
||||||
@ -29,6 +29,11 @@ class Actor:
|
|||||||
cfg.error_bands.on_click(plt.show_error_bands)
|
cfg.error_bands.on_click(plt.show_error_bands)
|
||||||
cfg.error_bars.on_click(plt.show_error_bars)
|
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):
|
def delete(self):
|
||||||
self.cache = None
|
self.cache = None
|
||||||
|
@ -1,14 +1,26 @@
|
|||||||
from bokeh.models import TextInput
|
from bokeh.models import Select, TextInput
|
||||||
|
|
||||||
from ..buki import Column
|
from ..buki import Column
|
||||||
|
|
||||||
|
|
||||||
|
CMAPS = [
|
||||||
|
"Plasma",
|
||||||
|
"Turbo",
|
||||||
|
"Viridis"
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
class ConfigDialog2D(Column):
|
class ConfigDialog2D(Column):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.ti_cache_size = ti_cache_size = TextInput(value="", title="Cache size:")
|
self.ti_cache_size = ti_cache_size = TextInput(value="", title="Cache size:")
|
||||||
ti_cache_size.disabled = True # 2D plot only shows the latest image
|
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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ import numpy as np
|
|||||||
|
|
||||||
from bokeh.plotting import figure
|
from bokeh.plotting import figure
|
||||||
from bokeh.models import ColumnDataSource, ColorBar, LinearColorMapper
|
from bokeh.models import ColumnDataSource, ColorBar, LinearColorMapper
|
||||||
|
from bokeh.palettes import all_palettes
|
||||||
|
|
||||||
from ..buki import Object
|
from ..buki import Object
|
||||||
|
|
||||||
@ -15,7 +16,8 @@ class Plot2D(Object):
|
|||||||
|
|
||||||
self.source = source = ColumnDataSource(data=data)
|
self.source = source = ColumnDataSource(data=data)
|
||||||
|
|
||||||
cmap = LinearColorMapper(palette="Viridis256")
|
self.cmap = cmap = LinearColorMapper()
|
||||||
|
self.change_cmap("Viridis")
|
||||||
cbar = ColorBar(color_mapper=cmap)
|
cbar = ColorBar(color_mapper=cmap)
|
||||||
|
|
||||||
fig = figure(name=name, match_aspect=True)
|
fig = figure(name=name, match_aspect=True)
|
||||||
@ -33,4 +35,9 @@ class Plot2D(Object):
|
|||||||
self.source.data.update(image=[image])
|
self.source.data.update(image=[image])
|
||||||
|
|
||||||
|
|
||||||
|
def change_cmap(self, name):
|
||||||
|
self.palette = name
|
||||||
|
self.cmap.palette = all_palettes[name][256]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user