added tooltips

This commit is contained in:
2021-06-11 17:58:11 +02:00
parent ea5cf1e9bc
commit c8ea2d5fc0
4 changed files with 44 additions and 3 deletions

View File

@ -1,10 +1,24 @@
import numpy as np import numpy as np
from bokeh.layouts import row from bokeh.layouts import row
from bokeh.models import ColumnDataSource from bokeh.models import ColumnDataSource, HoverTool
from bokeh.plotting import figure from bokeh.plotting import figure
from ..buki import Object from ..buki import Object
from ..utils import make_tooltips
TOOLTIPS_TIMESERIES = make_tooltips(
x = "$x",
y = "$y",
)
TOOLTIPS_HISTO = make_tooltips(
x = "$x",
y = "$y",
bin = "@left",
entries = "@top"
)
class Plot0D(Object): class Plot0D(Object):
@ -41,6 +55,9 @@ class TimeSeries:
fig.step(x="x", y="y", source=source, mode="after") fig.step(x="x", y="y", source=source, mode="after")
fig.circle(x="x", y="y", source=source) fig.circle(x="x", y="y", source=source)
hover = HoverTool(tooltips=TOOLTIPS_TIMESERIES, mode="vline")
fig.add_tools(hover)
def set(self, times, values): def set(self, times, values):
data = { data = {
@ -66,6 +83,9 @@ class Histo:
self.fig = fig = figure() self.fig = fig = figure()
fig.quad(left="left", right="right", top="top", bottom=0, source=source) fig.quad(left="left", right="right", top="top", bottom=0, source=source)
hover = HoverTool(tooltips=TOOLTIPS_HISTO, mode="vline")
fig.add_tools(hover)
def set(self, values): def set(self, values):
data = hist(values) data = hist(values)

View File

@ -1,15 +1,21 @@
import numpy as np import numpy as np
from bokeh.models import ColumnDataSource, DataRange1d, Band, Whisker from bokeh.models import ColumnDataSource, DataRange1d, Band, Whisker, HoverTool
from bokeh.palettes import Category10_10 from bokeh.palettes import Category10_10
from bokeh.plotting import figure from bokeh.plotting import figure
from ..buki import Object from ..buki import Object
from ..utils import make_tooltips
BLUE = Category10_10[0] BLUE = Category10_10[0]
RED = Category10_10[3] RED = Category10_10[3]
TOOLTIPS = make_tooltips(
x = "$x",
y = "$y",
)
class Plot1D(Object): class Plot1D(Object):
@ -29,6 +35,9 @@ class Plot1D(Object):
y_range = DataRange1d(only_visible=True, range_padding=0.5) y_range = DataRange1d(only_visible=True, range_padding=0.5)
fig = figure(name=name, y_range=y_range) fig = figure(name=name, y_range=y_range)
hover = HoverTool(tooltips=TOOLTIPS, mode="vline")
fig.add_tools(hover)
self.line_latest, self.circle_latest, self.errband_latest, self.errbars_latest = add_curve(fig, source, "x", "y", "y-std", "y+std", BLUE) self.line_latest, self.circle_latest, self.errband_latest, self.errbars_latest = add_curve(fig, source, "x", "y", "y-std", "y+std", BLUE)
self.line_average, self.circle_average, self.errband_average, self.errbars_average = add_curve(fig, source, "x", "avg", "avg-err", "avg+err", RED) self.line_average, self.circle_average, self.errband_average, self.errbars_average = add_curve(fig, source, "x", "avg", "avg-err", "avg+err", RED)

View File

@ -5,6 +5,14 @@ from bokeh.plotting import figure
from ..colormaps import cmaps from ..colormaps import cmaps
from ..buki import Object from ..buki import Object
from ..utils import make_tooltips
TOOLTIPS = make_tooltips(
x = "$x",
y = "$y",
z = "@image",
)
class Plot2D(Object): class Plot2D(Object):
@ -24,7 +32,7 @@ class Plot2D(Object):
self._update_cmap() self._update_cmap()
cbar = ColorBar(color_mapper=cmap) cbar = ColorBar(color_mapper=cmap)
fig = figure(name=name, match_aspect=True) fig = figure(name=name, match_aspect=True, tooltips=TOOLTIPS)
fig.image(source=source, x=0, y=0, dw=1, dh=1, color_mapper=cmap) fig.image(source=source, x=0, y=0, dw=1, dh=1, color_mapper=cmap)
fig.x_range.range_padding = 0 fig.x_range.range_padding = 0

View File

@ -19,4 +19,8 @@ def adjust_margin(obj, top=0, right=0, bottom=0, left=0):
obj.margin = [m + d for m, d in zip(obj.margin, delta)] obj.margin = [m + d for m, d in zip(obj.margin, delta)]
def make_tooltips(**kwargs):
return list(kwargs.items())