question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

px animations does not show correctly colors if all colors are not in the first frame

See original GitHub issue

For example

import pandas as pd
import plotly.express as px
dataVals = {
    'Lat': [39.783730, 7, 39.783730, 39.783730, 20, -4.03, 39.783730, 36.82, 39.783730],
    'Lon': [-100.445882, 66, -100.445882, -100.445882, 70, 5.33, -100.445882, -1.29, -100.445882],
    'Value': [40, 12, 22, 3, 60, 23, 30, 100, 200],
    'Year': ['1985', '1990', '1990', '1990', '1990', '1990', '2000', '2000', '2000'],
    'Continent Color': ["a", "b", "a", "a", "b", "c", "b", "d", "a"]
    }
data = pd.DataFrame(dataVals)

fig = px.scatter_geo(data, lat="Lat", lon="Lon", size="Value", color="Continent Color",
                     animation_frame="Year", animation_group="Continent Color",
                     projection="natural earth", size_max=200)

fig.show()

(all points are displayed with the color of continent “a”). Reported by https://community.plot.ly/t/scatter-geo-only-shows-values-with-a-certain-color-if-i-have-multiple-years-as-the-same-year/35976. Other functions such as px.scatter have the same problem.

If all colors are used for the first frame, the problem disappears.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:4
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
hlgirardcommented, Jun 25, 2020

Are there any plans to improve this feature to make it work as expected? I use animation_frame a lot to group data that belongs together in conjunction with color and would love to be able to leverage the expected behavior.

0reactions
fingerpartyycommented, Nov 15, 2022

hello @emmanuelle . I found a workaround for this, because i am also having trouble with animation on px. I didn’t modified the df, but i changed the approach of the color variable from categorical to numeric:

  • creating a new column, then
  • including color_continuous_scale and range_color variables

Here is the modified code. Hopefully it will help others:

def dummy_scatter():
    dataVals = {
        'Lat': [39.783730, 7, 39.783730, 39.783730, 20, -4.03, 39.783730, 36.82, 39.783730],
        'Lon': [-100.445882, 66, -100.445882, -100.445882, 70, 5.33, -100.445882, -1.29, -100.445882],
        'Value': [40, 12, 22, 3, 60, 23, 30, 100, 200],
        'Year': ['1985', '1990', '1990', '1990', '1990', '1990', '2000', '2000', '2000'],
        'Continent Color': ["a", "b", "a", "a", "b", "c", "b", "d", "a"]
        }
    data = pd.DataFrame(dataVals)
    data['ContinentColorNumber']=data['Continent Color']
    colordictContinent={'a':1,'b':2,'c':3,'d':4}
    data.ContinentColorNumber.replace(colordictContinent,inplace=True)
    
    fig = px.scatter_geo(data, 
                         lat="Lat", lon="Lon", 
                         size="Value", 
                         color="ContinentColorNumber",
                         color_continuous_scale='thermal',
                         range_color=(data.ContinentColorNumber.min(),data.ContinentColorNumber.max()),
                         projection="natural earth", 
                         animation_frame="Year",
                         size_max=20)
    
    return fig

dummy_scatter()

Capture2

Read more comments on GitHub >

github_iconTop Results From Across the Web

Plotly: How to make data consistent across animation frames ...
Animations are designed to work well when each row of input is present across all animation frames, and when categorical values mapped to...
Read more >
animation on procreate
Create a new layer above the first (background) and draw the first frame for the animation. Don't fill the entire animation layer with...
Read more >
Motion components | Framer for Developers
Complex strings containing multiple numbers and/or colors (ie "10px 0 #000" ). When animating to a non-animatable value like "block" , this value...
Read more >
Animation | Jetpack Compose - Android Developers
.background(Color.Red) ) { // Content of the notification… } } } In some cases, you may want to have AnimatedVisibility apply no animations...
Read more >
CSS Animations - W3Schools
To use CSS animation, you must first specify some keyframes for the animation. ... If the animation-duration property is not specified, no animation...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found