Show HN: Matplotloom: Weave frames into Matplotlib animations simply and quickly
I just wrote up a small package, matplotloom [1], to simplify and speed up making animations with matplotlib. I've also written some documentation [2]. It's published on PyPI [3] so you can install it with pip, poetry, or conda.

[1]: https://github.com/ali-ramadhan/matplotloom

[2]: https://aliramadhan.me/matplotloom/

[3]: https://pypi.org/project/matplotloom/

You can see some examples on the GitHub README or in the documentation.

What does matplotloom do?

To visualize simulation output for computational fluid dynamics I've had to make long animations with complex figures for a long time. The animations consist of thousands of frames and the figures are too complex for `FuncAnimation` and `ArtistAnimation`. I would always end up saving a bunch of still images and use ffmpeg to create animations from them. This package basically automates this process.

The main idea behind matplotloom is to describe how to generate each frame of your animation from scratch, instead of generating an animation by modifying one existing plot. This simplifies generating animations. See the example below and how the code inside the `for` loops is plain and familiar matplotlib. It also ensures that every feature can be animated and that the generation process can be easily parallelized.

import numpy as np
import matplotlib.pyplot as plt
from matplotloom import Loom

with Loom("sine_wave_animation.gif", fps=30) as loom:
for phase in np.linspace(0, 2*np.pi, 100):
fig, ax = plt.subplots()

x = np.linspace(0, 2*np.pi, 200)
y = np.sin(x + phase)

ax.plot(x, y)
ax.set_xlim(0, 2*np.pi)

loom.save_frame(fig)

This produces this gif animation [4]. More examples in the docs.

[4]: https://github.com/ali-ramadhan/matplotloom/raw/main/example...

Target Audience

You might find matplotloom useful if:

1. you just want to make animations quickly and easily.

2. you need to create complex animations (many subplots, many different plot types) and are encountering the limitations of matplotlib and existing packages.

3. you, like me, find `FuncAnimation` and `ArtistAnimation` difficult and limiting to use.

4. you need to create long animations quickly. Think thousands of frames.

Comparison

I think matplotloom is simpler to user than other methods of making animations with matplotlib, making it easier to start/pick up and iterate on your animations. It works out-of-the-box on anything matplotlib. The simplicity and flexibility comes at the cost of speed, but matplotloom makes it easy to parallelize frame creation so you can create big animations much more quickly.

Some comparisons:

* matplotlib itself has two tools for making animations: `FuncAnimation` and `ArtistAnimation`. But to use them you have to write your plotting code differently to modify an existing frame. This makes it difficult to go from plotting still figures to making animations. And some features are non-trivial to animate.

* celluloid [5] is a nice package for making matplotlib animations easily, but as it relies on `ArtistAnimation` under the hood it does come with some limitations [6] such as not being able to animate titles. It also hasn't been maintained since 2018.

* animatplot [7] is also a nice package for making matplotlib animations. But it relies on `FuncAnimation` and has its own abstractions (blocks) for different plot types so you can't animate every plot type (or plots produced by packages built on top of matplotlib like pandas or Cartopy). It hasn't been maintained since 2020.

[5]: https://github.com/jwkvam/celluloid

[6]: https://github.com/jwkvam/celluloid?tab=readme-ov-file#limit...

[7]: https://github.com/t-makaro/animatplot