To add hover tooltips in Bokeh, pass tooltips= to figure(): a list of (label, value) pairs where "@column" pulls a value from the glyph's data source. Use a HoverTool object when you need date formats, line-following behavior or tooltips on only some glyphs. This post uses Bokeh 3.10.
Quick Example
Rent against floor area for 90 sample apartments. Hover over a point to see its district, size and rent.
import numpy as np
import pandas as pd
from bokeh.plotting import figure, show
from bokeh.transform import factor_cmap
rng = np.random.default_rng(8)
districts = ["Old Town", "Riverside", "Hillcrest"]
premium = {"Old Town": 420, "Riverside": 180, "Hillcrest": 0}
district = rng.choice(districts, 90)
area = rng.uniform(28, 110, 90).round()
rent = (520 + 13.5 * area + np.array([premium[d] for d in district])
+ rng.normal(0, 110, 90)).round()
df = pd.DataFrame({"district": district, "area": area, "rent": rent,
"per_m2": rent / area})
p = figure(
title="Monthly rent by floor area", x_axis_label="Floor area (m²)",
y_axis_label="Rent ($)", height=420, sizing_mode="stretch_width",
tooltips=[
("District", "@district"),
("Area", "@area m²"),
("Rent", "$@rent{0,0}"),
("Per m²", "$@per_m2{0.00}"),
],
)
p.scatter("area", "rent", source=df, size=10, alpha=0.8, legend_group="district",
color=factor_cmap("district", ["#d9480f", "#1971c2", "#5c940d"], districts))
p.legend.location = "top_left"
show(p)
Rent rises with floor area in all three districts, and Old Town apartments sit above the others at the same size. The text in braces is a format: {0,0} adds a thousands separator and {0.00} keeps two decimals.
What Can Go in a Tooltip?
| In a tooltip string | Shows |
|---|---|
@rent |
The value of the rent column for the hovered point |
@{floor area} |
A column whose name has spaces |
@rent{0,0} |
The column with a number format |
$index |
The row number in the data source |
$x, $y |
The mouse position in data units |
$sx, $sy |
The mouse position in screen pixels |
$name |
The name of the hovered glyph |
@ refers to your data, and $ refers to the plot. A literal dollar sign in front of a field, as in $@rent, prints as a dollar sign.
If a tooltip shows ???, the column name doesn't match anything in that glyph's source. Passing arrays to a glyph (p.scatter(df["area"], df["rent"])) creates a source with only x and y, so pass source=df and column names when the tooltip needs other columns.
Use HoverTool for More Control
tooltips= on a figure is a shortcut for adding a HoverTool. Creating the tool yourself lets you attach it to particular glyphs with renderers.
from bokeh.models import HoverTool
p = figure(height=360, sizing_mode="stretch_width",
title="Tooltips on the points only, not the trend line")
points = p.scatter("area", "rent", source=df, size=9, color="#495057",
hover_fill_color="#f59f00", hover_line_color="#f59f00")
fit = np.polyfit(df["area"], df["rent"], 1)
xs = np.array([28, 110])
p.line(xs, np.polyval(fit, xs), line_width=3, color="#e03131")
p.add_tools(HoverTool(renderers=[points],
tooltips=[("Rent", "$@rent{0,0}"), ("Area", "@area m²")]))
show(p)
The hover_fill_color and hover_line_color arguments highlight the point under the mouse.
Tooltips on a Line Chart
By default a line shows a tooltip only when the mouse touches it. mode="vline" shows the value at the mouse's x position instead. Dates need two things: a {%F}-style format and a matching entry in formatters.
days = pd.date_range("2026-01-01", periods=90)
temps = pd.DataFrame({
"day": days,
"inside": 20.5 + rng.normal(0, 0.35, 90),
"outside": 2 + 9 * np.linspace(0, 1, 90) ** 2 + rng.normal(0, 1.8, 90),
})
p = figure(x_axis_type="datetime", height=360, sizing_mode="stretch_width",
title="Indoor and outdoor temperature")
p.line("day", "inside", source=temps, line_width=2, color="#e8590c")
outside = p.line("day", "outside", source=temps, line_width=2, color="#1c7ed6")
p.add_tools(HoverTool(
renderers=[outside], # one tooltip that reports both columns
mode="vline",
tooltips=[("Date", "@day{%b %d}"), ("Inside", "@inside{0.0} °C"),
("Outside", "@outside{0.0} °C")],
formatters={"@day": "datetime"},
))
show(p)
Without renderers, a vline tool shows one tooltip per line at the same time. Pointing it at one line and listing both columns keeps a single box.
Custom HTML Tooltips
Pass an HTML string as tooltips to design the whole box. The @ fields and formats work inside it.
card = """
<div style="padding:4px 8px; min-width:150px;">
<div style="font-size:15px; font-weight:bold; color:@color;">@district</div>
<div>@area m² for <b>$@rent{0,0}</b></div>
<div style="color:#868e96;">$@per_m2{0.00} per m²</div>
</div>
"""
palette = {"Old Town": "#d9480f", "Riverside": "#1971c2", "Hillcrest": "#5c940d"}
cards = df.assign(color=df["district"].map(palette))
p = figure(height=360, sizing_mode="stretch_width", tooltips=card,
title="Custom HTML tooltip")
p.scatter("area", "per_m2", source=cards, color="color", size=10)
show(p)
Smaller apartments cost more per square meter. Values from your data are escaped before they go into the tooltip. If a column holds HTML that you trust and want rendered, use @column{safe}.
Tooltips on Bars and Stacked Bars
Bars work the same way as points. On a stacked chart, $name is the column of the hovered segment and @$name is its value.
visits = pd.DataFrame({
"month": ["Jan", "Feb", "Mar", "Apr", "May"],
"Adults": [820, 760, 910, 1180, 1340],
"Children": [310, 280, 420, 690, 730],
})
p = figure(x_range=list(visits["month"]), height=340, sizing_mode="stretch_width",
title="Museum visits", toolbar_location=None,
tooltips=[("Group", "$name"), ("Visits", "@$name{0,0}"),
("Month", "@month")])
p.vbar_stack(["Adults", "Children"], x="month", source=visits, width=0.7,
color=["#364fc7", "#fab005"], legend_label=["Adults", "Children"])
p.y_range.start = 0
p.legend.location = "top_left"
show(p)
Practical Tips
- Hover needs a mouse. On touch screens people tap, so don't hide information that matters only in tooltips.
- Overlapping points produce stacked tooltips. Smaller markers or
point_policy="follow_mouse"help with placement, but dense data is better aggregated or shaded. - A
{%b %d}format works only whenformattersmarks that field as"datetime".




