Reputation: 1652
I have a problem with matplotlib animation in my Python script on Mac OS.
The full script is here (it's a bit long), and the animation part is here:
# ...
ani = animation.FuncAnimation(
fig,
animate,
np.arange(m),
interval=tint,
blit=True,
repeat=False
)
plt.show()
The problem I've encountered is that the animation works just fine on Windows and Linux, but on Mac OS the animation doesn't show up. Here's a video demonstration.
On all three systems (Windows, Linux and Mac OS) I only installed matplotlib
and numpy
packages to run the script, I didn't install anything aside of these, so all three (should) have the same packages. Just in case, here's a summary of their environments:
# Windows (10.19041.450, x64)
- Python 3.7.2
- matplotlib 3.3.1
- numpy 1.19.1
# Linux (Ubuntu 20.04.1, x64)
- Python 3.8.2
- matplotlib 3.3.1
- numpy 1.19.1
# Mac OS (10.15.6, x64)
- Python 3.8.5
- matplotlib 3.3.1
- numpy 1.19.1
I've tried other simple plot animation samples (for example the ones from matplotlib documentation), and they work fine on Mac OS, so I would guess there is something wrong with my particular script, but the fact that this very same script works on Windows and Linux (though with a different animation speed, for some reason) confuses me a lot.
I've also tested my script on 3 other Macs with different Mac OS and Python versions installed, but it was all the same.
Do you see any reason why my script doesn't show animation on Mac OS?
Upvotes: 2
Views: 1324
Reputation: 1652
I've discovered that in my case the default matplot backend is MacOSX
, and apparently this one is not capable of doing my animation (for whatever reasons).
And the backend that is capable turned out to be TkAgg
. So after setting it like this:
matplotlib.use("TkAgg")
I now get the animation in my script on Mac OS too.
If you are interested in more details, I wrote a blog post about it.
Upvotes: 1