I created a choropleth map using plotly express's function choropleth() Code is below.
fig = px.choropleth(df_countrydate,
locations="Country",
locationmode = "country names",
color="Confirmed",
hover_name="Country",
animation_frame="Date",
color_continuous_scale="Reds"
)
fig.update_layout(
title_text = 'Global Spread of Coronavirus',
title_x = 0.5,
geo=dict(
showframe = False,
showcoastlines = False,
))
iplot(fig)
It's a dynamic map and I was wondering if there was anyway I could speed up the transitions from one date to the next when I hit play.
Change these 2 parameters in your plot:
fig.layout.updatemenus[0].buttons[0].args[1]['frame']['duration'] = 30
fig.layout.updatemenus[0].buttons[0].args[1]['transition']['duration'] = 5
Time is in milliseconds
I got the answer from the code of this video: https://www.youtube.com/watch?v=RCUrpCpGZ5o&t=1156s&ab_channel=CharmingData You can find the whole code here: https://github.com/Coding-with-Adam/Dash-by-Plotly/blob/master/Plotly_Graphs/Animated_Scatter/gender_ineq.py
I also found that the resolution of the map (110 vs 50) really impacts the refresh rate of the animation. In my project displaying the evolution of a variable was more relevant than the detail, since my intention was presenting the change over time of said variable. I considered it was less likely for users to try to zoom in the map, so I decided to use the lower resolution map (1:110m vs 1:50m):
fig.update_geos(projection_type="equirectangular", visible=True, resolution=110)
All those options combined resulted in a fast and smooth animation for my map after lowering the frame and animation duration. With resolution=50, I couldn't see any effect when changing the duration values.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With