Skip to content

Allow customization of the first line of the hovertext in x/y unified hovermode #7427

Open
@celia-lm

Description

@celia-lm

Following this forum thread: https://community.plotly.com/t/customizing-text-on-x-unified-hovering/39440

Other examples from the forum:

The default value for the heading (first line of the hover content)is x value in "x unified" and y value in "y unified". It is already possible to customize the format of the x/y value by using xhoverformat and yhoverformat, respectively:

fig.update_traces(xhoverformat="%b") # for x unified
fig.update_traces(yhoverformat="Month: %b") # for y unified

Ref: https://plotly.com/python/hover-text-and-formatting/#hover-templates-with-mixtures-of-period-data

In the forum thread, a workaround is shared for other scenarios: https://community.plotly.com/t/customizing-text-on-x-unified-hovering/39440/26

This workaround requires adding a new trace with the information that the developer wants to show hardcoded:

hov_text= [f'🌀 Wind Speed <br><br>{d}<br>Daily average: {w} km/h'
           for d, w in zip(dff['date'].dt.strftime('%B %d,%Y'), dff['wind_daily_average'])]

fig = go.Figure()
fig.add_scatter(hovertext=hov_text, hoverinfo='text', ...)

The requested feature would allow the developer to specify the variable or value directly without needing to manually create the text for each x value. It could look like this:

# remove title
fig.update_layout(hovertitle = dict(text=None))

# same title for every x value
fig.update_layout(hovertitle = dict(text="Always the same title"))

# set it to a df variable that is not the x value, or that is a combination of values (similar to the current workaround)
fig.update_layout(hovertitle = dict(text=df["my_custom_value"]))
fig.update_layout(hovertitle = dict(text=f'Max stock price in period: {df["max_by_quarter"]}'))

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2considered for next cyclecscustomer successfeaturesomething new

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions