plt.savefig would draw itLines marked in teal change with the chart: the year, hidden continents, followed countries. It is the code from the lecture plus one new line, df = gm[gm['year'] == year], which keeps only the rows of one year. The data file has the same columns as the lecture's 2007 file. Between two data years the page blends the bubbles smoothly; Python only knows the 12 data years.
Put the drawing code into a function of year (it still uses gm and continent_colors from the code above). Then FuncAnimation calls that function once for every year in frames and glues the pictures together into an animation. It needs the same fixed axis limits for every frame, or the axes would jump around.
In Google Colab, show the animation in the notebook with from IPython.display import HTML and HTML(anim.to_jshtml()), or save it as a GIF with anim.save("gapminder.gif").
Keyboard: space play/pause, ← → previous/next year. Data: Gapminder, 142 countries, every fifth year 1952–2007 (the classic dataset; the lecture uses its 2007 rows).
Built to accompany COSC 1210 (CS I, Python), lecture “Basic Plots with Matplotlib”. Every frame is drawn live in your browser from the data, with the lecture's settings: s = 2 * pop / 1e6, alpha=0.6, the continent colors, a log x-axis with ticks 1k, 10k, 100k. The idea of the animated bubble chart comes from Hans Rosling's Gapminder.