Matplotlib Animation (Boids Part 2)

For part 2, I’d like to cover a tutorial in matplotlib that is our boid GUI. As far as my Googling skills could take me, I couldn’t find an animation similar to what I was looking for: two separate scatter plots that logically trace each other in an endless loop. The closest I could find was a cool rain simulation that used a scatter plot and randomly changed certain properties. Here is a time lapse video of my process from start to finish.

So first thing is housekeeping. There are a few imports that need to happen. I’m on a MacOS and using PyCharm as my IDE. I did get a few errors installing the following:

Imports

If you’re getting the same problem, try running

 pip3 install numpy

It’s likely numpy was trying to install for Python 2.7 instead of Python 3. Next, we have to set up the plot.

Figure Set up
Matplotlib requires a figure object, think “blank canvas”. We can then draw our axes and data points over it. Creating an axes object lets us customize the x-y limit and appearance. Similarly, data points must also be objects. We achieve this by creating zero arrays in numpy. These are