Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
celia-lm opened this issue May 27, 2025 · 0 comments
Labels
cs customer success feature something new P2 considered for next cycle

Comments

@celia-lm
Copy link

celia-lm commented May 27, 2025

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"]}'))
@celia-lm celia-lm added feature something new cs customer success labels May 27, 2025
@gvwilson gvwilson added the P2 considered for next cycle label May 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cs customer success feature something new P2 considered for next cycle
Projects
None yet
Development

No branches or pull requests

2 participants