Cannot disable hoverinfo on a plotly express figure object

In the follwoing small Dash app:

df = pd.read_csv(...)
fig = px.line(x=.., y=.., color=..., template='presentation')
fig.update_traces(mode='lines+markers', hoverinfo='skip')
app = dash.Dash(__name__)
app.layout = htmlDiv([dcc.Graph(figure=fig)])

I still see hover popups on all traces, although I explicitly disable them via hoverinfo='skip'.

Do I have to use a call to another fig.update_.. method? I would like to keep the figure instantiation via fig = px.line(....

Thanks for any pointers.

1 Like

Ah, sorry this is confusing… 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() call.

4 Likes

Thanks @nicolaskruchten. That works well.

I have a related question. In Plotly Express, I would like ONLY the text from hover_name to appear on my hover popups. I’ve tried various combinations with no success. How can I suppress the default hoverinfo and only show the bold text from hover_name?

The following still shows hoverinfo for color, x and y:

fig = px.scatter(boxplot_data, 
                 x="Current Applet Installs", 
                 y="Potential Applet Installs",
                 log_x=True, log_y=True,
                 hover_name="hover_name",
                 color="higher_order_cat",
                 color_discrete_sequence=["dodgerblue", "limegreen", "orange", "red"],
                )

fig.update_traces(
   # hovertemplate=None,
   hoverinfo='skip'
)
1 Like

@TPN

You can use string interpolation combined with the hovertemplate attribute in order to get the effect you are looking for.

import plotly.express as px

hover_name = "hover_name"

fig = px.scatter(x=[1, 2, 3, 4, 5], 
                 y=[1, 2, 3, 4, 5],
                )

fig.update_traces(
   hovertext=hover_name, 
    hovertemplate=f'<b>{hover_name}<b>'
)

fig.show()
2 Likes

you saved me! thank you