✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🐇 Announcing Dash VTK for 3d simulation graphics. Check out the March webinar.

Hovermode: How to get rid of a trace in 'x' or 'y unified'

Hello, how would you go about in eliminating or getting rid of the trace-legend inside a hovermode window, especifically in ‘x unified’ or ‘y unified’?

For example, in this simple code with hovermode ‘x unified’, how do i get rid of the trace as shown in the photo?

import plotly.express as px

df = px.data.gapminder().query("continent=='Oceania'")

fig = px.line(df, x="year", y="lifeExp", color="country", title="layout.hovermode='x unified'")
fig.update_traces(mode="markers+lines", hovertemplate=None)
fig.update_layout(hovermode="x unified")

fig.show()

Hi @kennethv15 welcome to the forum! It’s not possible to remove this part of the legend, You can hack this behaviour by adding traces with a zero-line width as below, but this is just a hack :slightly_smiling_face:

import plotly.express as px

df = px.data.gapminder().query("continent=='Oceania'")

fig = px.line(df, x="year", y="lifeExp", color="country", title="layout.hovermode='x unified'")
fig.update_traces(mode="markers+lines", hovertemplate=None, hoverinfo='skip')
fig2 = px.line(df, x="year", y="lifeExp", color="country", 
                  title="layout.hovermode='x unified'")
fig2.update_traces(hovertemplate=None, line_width=0)
fig.add_traces(fig2.data)
fig.update_layout(hovermode="x unified")
fig.show()