Paul H Paul H - 4 months ago 12
Python Question

Using the hover tool with vbar glyphs

Question



Is it possible to use the hover tool with bokeh
vbar
glyphs?

Problem



Using the same basic setup, I can get great tool tips with the hover tool on
circle
glyphs, but not
vbar
glyphs

Demonstration



Setup



import numpy
import pandas
from bokeh import charts, plotting, models
plotting.output_notebook()

blue = 'STEELBLUE'
green = 'FORESTGREEN'

datalist = [
{'month': 'Oct', 'rain': 131., 'snow': 0.0, 'wy_month': 1},
{'month': 'Nov', 'rain': 12.4, 'snow': 0.0, 'wy_month': 2},
{'month': 'Dec', 'rain': 43.0, 'snow': 13.5, 'wy_month': 3},
{'month': 'Jan', 'rain': 63.0, 'snow': 9.2, 'wy_month': 4},
{'month': 'Feb', 'rain': 72.6, 'snow': 35.3, 'wy_month': 5},
{'month': 'Mar', 'rain': 13.5, 'snow': 4.2, 'wy_month': 6},
{'month': 'Apr', 'rain': 107., 'snow': 1.5, 'wy_month': 7},
{'month': 'May', 'rain': 77.0, 'snow': 0.0, 'wy_month': 8},
{'month': 'Jun', 'rain': 107., 'snow': 0.0, 'wy_month': 9},
{'month': 'Jul', 'rain': 216., 'snow': 0.0, 'wy_month': 10},
{'month': 'Aug', 'rain': 76.8, 'snow': 0.0, 'wy_month': 11},
{'month': 'Sep', 'rain': 76.4, 'snow': 0.0, 'wy_month': 12}
]

data = pandas.DataFrame(datalist).assign(total=lambda df: df['rain'] + df['snow'])
source = plotting.ColumnDataSource(data)

tooltips = [
("month", "@month"),
("rain", "@rain"),
("snow", "@snow"),
]


Successful with
circle
glyphs



hover_circle = models.HoverTool(tooltips=tooltips)
TOOLS_circle = [hover_circle, models.ResizeTool(), models.ResetTool()]

fig = plotting.figure(width=600, height=300, y_range=(0, 250),
x_range=data['month'].tolist(),
tools=TOOLS_circle)
fig.circle(x='wy_month', y='rain', color=blue, source=source)
fig.circle(x='wy_month', y='snow', color=green, source=source)
plotting.show(fig)


enter image description here

Unsuccessful with
vbar
glyphs



hover_bar = models.HoverTool(tooltips=tooltips)
TOOLS_bar = [hover_bar, models.ResizeTool(), models.ResetTool()]

fig = plotting.figure(width=600, height=300, y_range=(0, 250),
x_range=data['month'].tolist(),
tools=TOOLS_bar)
fig.vbar(x='wy_month', bottom=0, top='rain', width=0.5, color=blue, source=source)
fig.vbar(x='wy_month', bottom='rain', top='total', width=0.5, color=green, source=source)
plotting.show(fig)


enter image description here

Answer

Not yet, as of Bokeh 0.12.1. Given the choice to add vbar/hbar without hit-testing support, or not add them at all, it was decided to be useful to the most number of users to make them available sooner rather than later. Adding hit-testing to these glyphs is a short term priority, though the team is stretched very thin at the moment. If you are interested in contributing, please reach out on GitHub.

Comments