#340 Scatterplot animation

#340 Scatter animation

The trick used to make animated plots is always the same: realise a set of several images, and display them one after another in a .gif file with Image Magick. Here I do a loop where each iteration make a scatterplot. The position of the unique dot slowly evolves. Then, I use a bash command line to transform the set of images in an animation!

# libraries
import matplotlib.pyplot as plt
import seaborn as sns


# I build a data set: 10 individuals and 5 variables for each
for i in range(0,10):
fig = plt.figure(figsize=(480/my_dpi, 480/my_dpi), dpi=my_dpi)
plt.scatter(i, i*i, s=40+i*600, alpha=0.5, edgecolors="grey", linewidth=2)
plt.xlim(0, 10)
plt.ylim(0, 100)
plt.savefig(filename, dpi=96)

Running these lines of code you should get several files in your working directory: step1.png, step2.png… Now we can use a Bash one liner to transform it in a gif:

# Then use image magick (this is bash, not python)
convert -delay 80 *.png animated_chart.gif

Leave a Reply

Your email address will not be published.