Hover Tooltips in Bokeh:

  • Hover tooltips let you point the mouse at a specific point in the plot and display associated information.
    • These tooltips represent attributes that add interactivity to the plot.

Create Hover Tooltips:

  • The HoverTool function is part of the bokeh.models module. The below code snippet demonstrates how to use the HoverTool function to create hover tooltips.
    • The HoverTool function is used to create a list of tuples. Each tuple contains the name of the information to be conveyed, such as the High Stock Price, and the associated column in which this information is found, such as @High.
    • We then pass this HoverTool object into the tools argument of the figure function while creating the figure.
python
1from bokeh.plotting import figure, show, output_notebook
2from bokeh.models import ColumnDataSource, HoverTool
3from bokeh.layouts import row
4import pandas as pd
5
6# --- snip ---
7
8# Create the tooltips
9hover_tool = HoverTool(tooltips=[
10    ("High Stock Price", "@High"), 
11    ("Low Stock Price", "@Low"), 
12    ("Closing Stock Price", "@Close")
13    ])
14
15# Create the figure
16fig = figure(tools=[hover_tool])
17
18# Show the figure
19show(fig)