Area chart hovertext problem

Iโ€™m trying to create an area chart with customized hovertext for each point. That is working, but the plot has the same text showing on each point, cluttering the presentation.

Code is as follows: (hovertext is a dataframe field showing exactly what should be shown)

fig = px.area(df_pbp, x=x_col, y=y_col_norm,
              text="hovertext",
              #hover_data=["hovertext"],
              color_discrete_sequence=["blue"],
              title="Win probabilities throughout game"
)

fig.update_traces(hovertemplate="%{text}",
                  showlegend=False)

How do I hide this text in the chart but still keep in the hovertext properly? Thanks.

hi @sberman
:wave: Welcome to the community.

Try to remove the text="hovertext", from the px.area(โ€ฆ). That should help.

Hereโ€™s an example with a customized hover, but without the text appearing.

import plotly.express as px

df = px.data.tips()
print(df.head())

fig = px.scatter(
    data_frame=df,
    x = 'day',
    y = 'tip'
)

fig.update_traces(
    hovertemplate=
    '<i>Tip</i>: $%{y:.1f}'+
    '<br><b>X</b>: %{x}<br>',
    showlegend = False)
fig.show()

You can read more about it in the hover formatting chapter.

You were right - I removed it as text, but had to add the โ€˜hovertextโ€™ field as custom_data, and then refer to customdata[0] in the hovertemplate. Thanks.