Utilizing animation frames to add a new layer to your plots
In the last examples, we set the year as a variable and got a snapshot of the desired indicator for that year. Since the years represent sequential values, and can also be used as a grouping variable, we can use the years in the animation_frame
parameter and make the chart interactive. This would introduce a new handle underneath the chart, where users can either drag to the desired year or press the play button to watch how the respective indicator progresses throughout the years. It would be a sequence of frames, like watching a video. What this does is that for a selected year, we will get a subset of the DataFrame where the rows in the year
column are equal to the selected year. The chart automatically updates with colors corresponding to the values of the year that was chosen.
Here is the updated code to produce an animated chart (by year):
fig = px.choropleth(poverty[poverty['is_country']],| Â ...