Hover Information
Customizing the tooltip — one of the most under-used interactive features
Every Plotly Express chart has hover tooltips for free. They show the x and y values of whatever you point at. With a little extra configuration, you can make the tooltip a mini information panel that turns each dot into a self-contained record.
This is one of the most under-used features of Plotly — and one of the highest-leverage. A great hover tooltip can answer questions that would otherwise require a separate table.
The default tooltip
Hover over any dot. You see gdpPercap = ... and lifeExp = ....
Useful but anonymous — you don't know which country.
hover_name: a headline for the tooltip
hover_name="column" puts the value of that column in bold at
the top of the tooltip.
Now each hover starts with the country name. Already a huge improvement.
hover_data: add or remove fields
hover_data=[...] adds extra columns to the tooltip. You can also
pass a dictionary to control formatting and visibility per field.
Now hovering shows continent, population, GDP, and life expectancy
— each formatted to read well. The format strings (":,",
":.0f", ":.1f") are Python's standard f-string mini-language.
Hiding default fields
If a field is already encoded in the chart (e.g., x="gdpPercap"),
it appears in the hover by default. To hide it:
hover_data={"gdpPercap": False}This is useful for keeping the tooltip clean.
Custom hover labels with units
You can also relabel hover fields using labels={} — the same
mapping you use for axis labels. Plotly Express reuses the labels
in the hover automatically.
Hover over a dot. The labels now read "GDP per capita (USD)" instead of "gdpPercap" — no separate hover-label configuration needed.
Format string reference
A handful of f-string formats cover 90% of needs:
| Format | Result | Use for |
|---|---|---|
:, | 1,234,567 | Thousands separator |
:.0f | 1235 | No decimals |
:.2f | 1234.57 | Two decimals |
:,.0f | 1,235 | Thousands, no decimals |
:.1% | 12.3% | Percentage |
:.2e | 1.23e+03 | Scientific notation |
:$,.0f | $1,235 | Dollars (in Plotly, use d3 spec) |
(Plotly hover formats use the same syntax as D3.js number formats, which is mostly the same as Python's.)
Why this matters: hover is the detail layer
Recall Ben Shneiderman's mantra: overview first, details on demand. The hover tooltip is the details-on-demand mechanism. A good hover lets the chart show summary structure (overview) while making every individual point queryable (detail).
A bare-default hover wastes that opportunity. Spend the extra 30 seconds.
Check your understanding
What does hover_name="country" do in a Plotly Express call?
Renames the country column.
Hides the country column from the data.
Sets the value of that column as a bold headline at the top of the hover tooltip for each data point.
Forces the chart to use country as the color.
Which hover_data value would format a population of 1234567 as "1,234,567"?
True
":.2f"
":,"
"%population%"
Why is a well-crafted hover tooltip valuable for analytical charts?
It makes the chart look more colorful.
It speeds up rendering.
It provides "details on demand" — the reader can investigate any individual data point without leaving the chart or consulting a separate table.
It is required for the chart to be interactive.