Unit 11.01: Hover text that says something the chart cannot
A hover should say something the chart cannot show.
Detail on demand, not a repeat of the axes
A hover template carrying a field that is not on either axis.
The code defines one and reports what it adds.
import plotly.graph_objects as go
fig = go.Figure(go.Scatter(
x=[1, 2, 3], y=[100, 108, 115],
customdata=[["North", "12 stores"], ["North", "12 stores"],
["North", "13 stores"]],
hovertemplate="Week %{x}<br>Revenue %{y}k<br>%{customdata[0]}, "
"%{customdata[1]}<extra></extra>"))
trace = fig.data[0]
print(f"hover template : {trace.hovertemplate}")
print(f"extra fields : {len(trace.customdata[0])} per point")
print(f"points : {len(trace.x)}")
print("""
The hover carries the store count -- something the chart cannot show without a
second axis. That is what interactivity is for: the detail that would clutter
the chart if it were always visible.
A hover that repeats the axis values adds a delay and nothing else.
""")
The hover carries the store count - something that would need a second axis or a second chart to display permanently. That is what interactivity is for: the detail that would clutter the chart if it were always visible.
A hover that repeats the x and y values adds a delay and nothing else. The reader could already read those.
The mistake this prevents
The mistake is accepting the default hover. It shows the coordinates, which is the information the reader is already looking at - so the interaction costs a movement and a wait to learn nothing.
Takeaway
Put something in the hover that is not on the axes. A hover repeating the coordinates is a delay with no payload.
