Dataslope logoDataslope

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

Code Block
Python 3.13.2

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.

Code Block
Python 3.13.2

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.

Code Block
Python 3.13.2

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.

Code Block
Python 3.13.2

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:

FormatResultUse for
:,1,234,567Thousands separator
:.0f1235No decimals
:.2f1234.57Two decimals
:,.0f1,235Thousands, no decimals
:.1%12.3%Percentage
:.2e1.23e+03Scientific notation
:$,.0f$1,235Dollars (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

QuestionSelect one

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.

QuestionSelect one

Which hover_data value would format a population of 1234567 as "1,234,567"?

True

":.2f"

":,"

"%population%"

QuestionSelect one

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.

On this page