Hi,
I am trying to plot a bunch of samples collected over time as lines in a bokeh-server app (following the example in data_tables, but adding the plot as part of the object (self.rawplot below). In a particular plot, there may be 20-50 lines. Each is rendered separately, via:
cps_glyph = Line(x=“time”, y=fileName, line_color = listOfTraceColours[i])
cps = GlyphRenderer(data_source=self.source, glyph = cps_glyph)
self.rawplot.renderers.append(cps)
This is called a bunch of times within a loop so that each line has a color related to what group of samples it belongs to.
My issue comes when I use the hover tool. I know that the hover tool doesn’t work with Line data, so I use Circle exactly the same as above:
cps_glyph_C = Circle(x=“time”, y=fileName) #, line_alpha = 0, fill_alpha = 0)
cps_C = GlyphRenderer(data_source=self.source, glyph=cps_glyph_C)
self.rawplot.renderers.append(cps_C)
Eventually, these circles will be invisible (hence the line and fill alpha = 0 bit). I add the hover tool via:
tooltips = [
("Time", "$x"),
("CPS", "$y"),
]
raw_hover_tool = HoverTool(plot=self.rawplot, tooltips=tooltips)
This works fine showing the x and y positions. However, I would love it if it was also able to display the name of the sample it was hitting. My guess is that it could return the name of the renderer it has hit, or something similar if the rendered had a name argument (e.g. cps_C = GlyphRenderer(data_source=self.source, glyph=cps_glyph_C, name=fileName).
Is there some workaround for this case. Any help would be much appreciated. Below is a bit more of my code to illustrate how I’m using it:
class DataTables(object):
def __init__(self):
self.document = Document()
self.session = Session()
self.session.use_doc('xxxxx')
self.session.load_document(self.document)
self.currentElement = "MyElement"
self.currentIS = "MyIS"
self.rawColNameMax = "jjj.csv"
self.normColNameMax = "jjj.csv"
self.uvColNameMax = "jjj.csv"
self.source = ColumnDataSource()
self.update_data()
self.document.add(self.create_plots())
self.session.store_document(self.document)
def create_plots(self):
xdr = DataRange1d(sources=[self.source.columns("time")])
ydr = DataRange1d(sources=[self.source.columns(self.rawColNameMax)])
self.rawplot = Plot(title=self.currentElement, x_range=xdr, y_range=ydr, plot_width=800, plot_height=300)
xaxis = LinearAxis(plot=self.rawplot, axis_label = "Time (s)")
xgrid = Grid(plot=self.rawplot, dimension=0, ticker=xaxis.ticker)
self.rawplot.below.append(xaxis)
yaxis = LinearAxis(plot=self.rawplot, axis_label = "Raw CPS")
ygrid = Grid(plot=self.rawplot, dimension=1, ticker=yaxis.ticker)
self.rawplot.left.append(yaxis)
for i, cluster in enumerate(clusterList):
for fileName in cluster:
if fileName in self.source.data.keys():
cps_glyph = Line(x="time", y=fileName, line_color = listOfTraceColours[i])
cps = GlyphRenderer(data_source=self.source, glyph = cps_glyph)
self.rawplot.renderers.append(cps)
cps_glyph_C = Circle(x="time", y=fileName) #, line_alpha = 0, fill_alpha = 0)
cps_C = GlyphRenderer(data_source=self.source, glyph=cps_glyph_C)
self.rawplot.renderers.append(cps_C)
tooltips = [
("Time", "$x"),
("CPS", "$y"),
]
raw_hover_tool = HoverTool(plot=self.rawplot, tooltips=tooltips)
raw_select_tool = BoxSelectTool(plot=self.rawplot, dimensions=['width'])
pan_tool = PanTool()
reset_tool = ResetTool()
resize_tool = ResizeTool()
wheelzoom_tool = WheelZoomTool()
raw_save_tool = PreviewSaveTool()
self.rawplot.tools.extend([pan_tool, raw_hover_tool, raw_select_tool, reset_tool, resize_tool, wheelzoom_tool, raw_save_tool])
self.rawplot.renderers.extend([cps, ygrid, xgrid])
overlay = BoxSelectionOverlay(tool=raw_select_tool)
self.rawplot.add_layout(overlay)
if name == “main”:
data_tables = DataTables()
data_tables.run(True)