[I originally posted this question on [SO](https://stackoverflow.com/q/46199911/671013)]
Problem setting Assume I have a pandas.DataFrame
which contains several columns and indexed by DatetimeIndex
:
np.random.seed(42)
df = pd.DataFrame(np.random.random(size=(10,3)),
columns=['foo', 'bar', 'goo'],
index=pd.date_range('20170101', periods=10)
)
The objective is to plot the three columns, having the index as the x-axis and enable a hovertool
vertically.
Here’s what I managed to have so far:
hovertool = bmo.HoverTool(
tooltips=[("index", "@index{%F}"),
("val", "$y{0,0.0}")],
formatters={'index' : 'datetime'})
p = bpl.figure(width=900, height=400, x_axis_type="datetime", tools=[hovertool])
for i, col in enumerate(ds.column_names[:-1]):
p.line('index', col, source=ds, color=Set2[4][i], legend=bcp.value(col))
bpl.show(p)
This works nicely and as expected (well depending on ones expectations). Anyways, if I replace it with:
hovertool = bmo.HoverTool(
tooltips=[("index", "@index{%F}"),
("val", "$y{0,0.000}")],
formatters={'index' : 'datetime'},
mode='vline' # Enabling the vertical behavior
)
p = bpl.figure(width=900, height=400, x_axis_type="datetime", tools=[hovertool])
for i, col in enumerate(ds.column_names[:-1]):
p.line('index', col, source=ds, color=Set2[4][i], legend=bcp.value(col))
bpl.show(p)
Then, two things doesn’t work:
- The labels are not aligned vertically (and show values for different x-positions)
- The value rendered is the one where the mouse is located, and not reflecting the right value of the other 2 curves.