Skip to content

[Bug] Hovertemplate not persisted after animation #2722

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

Closed
ogelin opened this issue Aug 24, 2020 · 5 comments
Closed

[Bug] Hovertemplate not persisted after animation #2722

ogelin opened this issue Aug 24, 2020 · 5 comments

Comments

@ogelin
Copy link

ogelin commented Aug 24, 2020

I've noticed this issue using Plotly with Dash & also reproduced in my own Jupyter notebook.

Here is a code sample reproducing the issue :

import plotly.express as px
df = px.data.gapminder()

fig = px.scatter(df, x="gdpPercap", y="lifeExp",
	         size="pop", color="continent", animation_frame='year', animation_group='country',
                 hover_name="country", log_x=True, size_max=60)

fig.update_traces(
        hovertemplate='<span>hi!!</span>',
    )

fig.show()

When the figure is initially loaded, the tooltips show my custom hover template. After the animation, my hover template is no longer in use and the tooltips show their initial content (i.e. the property names followed by an equal sign & their value).

Before animation:
image

After animation:
image

@nicolaskruchten
Copy link
Contributor

This is indeed surprising and annoying, but update_traces doesn't update traces in the animation frames at the moment, although it probably should! To do this today you will need to iterate across the traces in fig.frames and set the hovertemplate manually.

@MaxGhenis
Copy link
Contributor

MaxGhenis commented Aug 4, 2021

Thanks @nicolaskruchten, this worked for me:

CUSTOM_HOVERTEMPLATE = "<b>%{customdata[0]}</b><br>%{customdata[1]}<br>%{customdata[2]}"
fig.update_traces(hovertemplate=CUSTOM_HOVERTEMPLATE)
for frame in fig.frames:
    frame.data[0].hovertemplate = CUSTOM_HOVERTEMPLATE

@DaniloSI
Copy link

DaniloSI commented Dec 22, 2021

Thanks @nicolaskruchten, this worked for me:

CUSTOM_HOVERTEMPLATE = "<b>%{customdata[0]}</b><br>%{customdata[1]}<br>%{customdata[2]}"
fig.update_traces(hovertemplate=CUSTOM_HOVERTEMPLATE)
for frame in fig.frames:
    frame.data[0].hovertemplate = CUSTOM_HOVERTEMPLATE

Thanks @MaxGhenis! This worked for me too. But, in my case, I needed to iterate through frame.data.

My code looked like this:

fig.update_traces(hovertemplate=CUSTOM_HOVERTEMPLATE)

for frame in fig.frames:
    for data in frame.data:
        data.hovertemplate = CUSTOM_HOVERTEMPLATE

@chriscampana
Copy link

chriscampana commented Sep 13, 2022

I unfortunately cannot get either of these two workarounds to work using a choropleth or a choropleth_mapbox. Any advice ?

@gvwilson
Copy link
Contributor

gvwilson commented Jul 4, 2024

Hi - we are trying to tidy up the stale issues and PRs in Plotly's public repositories so that we can focus on things that are still important to our community. Since this one has been sitting for several years, I'm going to close it; if it is still a concern, please add a comment letting us know what recent version of our software you've checked it with so that I can reopen it and add it to our backlog. Thanks for your help - @gvwilson

@gvwilson gvwilson closed this as completed Jul 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants