Hovertemplate does not show 'name' property

Hello,

I’m trying to create a hovertemplate for a scatter plot to show the name of the data series, but when I hover over the series, all that shows is %{name}. The other chart properties, x, y, and text all display properly.

Below is the code I’m using:

fig.add_trace(go.Scatter(
                        x = timestamp_dates_slew, 
                        y = slew_duration_slew, 
                        name = VALID_SLEW_TO_MODES[j],
                        text = [f'{dt.datetime.strftime(d, "%Y-%m-%dT%H:%M:%S")}' for d in timestamp_dt],
                        mode = "markers",
                        hovertemplate = 
                        '%{name}' +
                        '<br><br>' +
                        '<b>Timestamp:</b> %{text}<br>' +
                        '<b>Duration:</b> %{y} sec<extra></extra>',
                        marker = dict(
                                size = 5,
                                color = COLORS[j]
                                ),
                        showlegend=True if VALID_SLEW_TO_MODES[j] not in trace_names else False), 
                        row=1, col=(SPACECRAFT_ID.index(sc)+1))

Below is the output

How can I get the series name to show up in the hoverdata?

Thank you for your help!

1 Like

Hi @ngaudio you could use the meta attribute to define values to be accessed within the hovertemplate, for example

name="my trace"
import plotly.graph_objects as go
fig = go.Figure(go.Scatter(x=[1, 2], y=[2, 1], name=name, meta=[name],
                          hovertemplate='%{meta[0]} Data %{y}'))
fig.show()

(or if you just want one meta value:

name="my trace"
import plotly.graph_objects as go
fig = go.Figure(go.Scatter(x=[1, 2], y=[2, 1], name=name, meta=name,
                          hovertemplate='%{meta} Data %{y}'))
fig.show()

)

5 Likes

Excellent! Thank you @Emmanuelle. It worked perfectly.

Could you please add these to:

Nowhere this meta attribute is mentioned??

2 Likes

Better yet, could there be a definitive resource on the available template variables for hovertemplate? I feel like this type of documentation is greatly missing.

3 Likes

Second this!!