Black Lives Matter. Please consider donating to Black Girls Code today.

Defining default/starting frame with Plotly Express Animation

I have two plotly express plots (one animated choropleth map and one animated barplot, see https://covid19mtl.ca/en) for which I’d like to display the last frame (the latest date) as the default/starting value.

So far, I’ve been able to change the default slider value, but this does not update the default frame in the plot (which remains the first frame). Is there a way I can force the plot to update after setting the slider value?

Example code in this notebook: https://colab.research.google.com/drive/1Qih2IjZLhwaxkAauyBnHQu96sCWner87

Thanks! :slight_smile:

Hi @jeremym,

This line of code updates your fig data and displays the last frame:

mtlmap_fig.update_traces(z=mtlmap_fig.frames[-1].data[0].z)
mtlmap_fig.show()
1 Like

Thanks!
I also had to update the hovertemplate so that it displayed the correct date.

mtlmap_fig.update_traces(z=mtlmap_fig.frames[-1].data[0].z, hovertemplate=mtlmap_fig.frames[-1].data[0].hovertemplate)