1

I am trying to plot stock data. X - axis has date values and Y - axis has a numeric value. A & B are two data frames. I am plotting multiple lines on the same plot using the below:

from bokeh.plotting import figure, show

p = figure(title="X", x_axis_label='Date', y_axis_label='MonthlyAvgPrice',x_axis_type="datetime", plot_width=1500)
p.line(A["Date"], A["Close"], legend_label="A", line_width=2, line_color="red")
p.line(B["Date"], B["Close"], legend_label="B", line_width=2)
show(p)

The chart is coming up fine. But I want to show tooltip values over hover. In the documentation I cant find a way to do that when there are more than one lines

EXODIA
  • 908
  • 3
  • 10
  • 28

1 Answers1

1

Add to your figure() call tooltips=[("(x, y)", "($x, $y)")].

I quote from the official website about parameters for figure:

tooltips An optional argument to configure tooltips for the Figure. This argument accepts the same values as the HoverTool.tooltips property. If a hover tool is specified in the tools argument, this value will override that hover tools tooltips value. If no hover tool is specified in the tools argument, then passing tooltips here will cause one to be created and added. (default: None)

The documentation of the Hovertool is here and an example is here.

If this is not what you need, you can add an Hovertool with self defined tooltips.

Example

from bokeh.models import HoverTool
from bokeh.plotting import figure, show, output_notebook
output_notebook()

p = figure(title="Figure with HoverTool")

l1 = p.line([1,2,3,4,5], [3,4,5,6,7], legend_label="A", line_width=2, line_color="red")
l2 = p.line([1,2,3,4,5], [1,2,3,4,5], legend_label="B", line_width=2)

p.add_tools(HoverTool(tooltips="y: @y, x: @x", renderers=[l1,l2], mode="vline"))
show(p)

Output

Lineplot with Hovertool

mosc9575
  • 5,618
  • 2
  • 9
  • 32