Spike Lines on, Floating hover data off

I want spikelines on, but absolutely no floating hover data text box because it ends up covering the horizontal spike line.

The closest I’ve gotten is fig.update_traces(hovertemplate=" ") (one space) which makes a very small empty text box but it still shows the name of the data line I hover over.

hovermode = None also turns off the spikelines. I’m doing this in Dash with the graph coming from plotly express from a px.line.

I have a checkbox that will, I hope, turn off the hover text and show the spikes instead (or maybe two checkboxes) but right now I can’t make the hover text go away and keep the spikelines.

Hi @marcosh,

You could use the hoverinfo property in your .update_traces() to control the hoverinfo on the graph.

With a graph_objects figure you could simply set hoverinfo='none' and disable the hoverinfo on the graph.

But Plotly Express uses the new hovertemplate mechanism for its hovers, so you’ll also need to set hovertemplate=None alongside hoverinfo='skip' in your .update_traces()

Here’s an example with px.line

import plotly.express as px

df = px.data.gapminder().query("country=='India'")

fig = px.line(df, x="year", y="lifeExp", color="country", title="Spike lines active")
fig.update_xaxes(showspikes=True)
fig.update_yaxes(showspikes=True)

fig.update_traces(hovertemplate=None, hoverinfo='none')

fig.update_layout(title="Spike lines active, hoverinfo off")

fig.show()
1 Like

Awesome, thank you! I decided that fully off may not be as good as hovermode='x' so I just put in radioitems choices for three hover text options (minimal, full, none). Implemented live now on my covid case tracker, thank you!

(Added a screenshot)

1 Like

Nice, such a cool dashboard @marcosh :slight_smile:

1 Like