pedagogic animations via python

Grant Sanderson a.k.a. 3blue1brown’s project manim is a curious passion project to create interactive python plot-compatible animations with mathematics, via code. It is youtube-famous. Here is a powerful example of what this tool can do. Most importantly, it makes me feel fancy. Here are some notes and links I need while using it.


Note dependencies:

sudo apt install libcairo2-dev libpango1.0-dev ffmpeg # Debian
brew install py3cairo ffmpeg pango scipy # macos
python -m pip install manim

Colaboratory and Binder installs available.


Tips and tricks

SVG height is not what it claims

From the documentation one might get the impression that the SVGMobject width and height parameters set width and height. Wrong; if I use both they only set the width. If I wanted to set the height, I needed to use the stretch_to_fit_height method.

def create_person(width=1.5, height=2.6, *_, color=PURPLE):
    person = SVGMobject(
        width=width, height=height,
    print("requested dims", width, height, "!=actual dims", person.get_width(), person.get_height())
    person = person.stretch_to_fit_width(width).stretch_to_fit_height(height)
    print("but after stretching we should match", person.get_width(), person.get_height())
    return person

Secret OpenGL mode

Undocumented, except for the distressingly vague and unofficial Manim OpenGL Renderer Usage Guide.

Fast (notionally) and interactive.

Possibly using OpenGL is as simple as passing the --renderer=opengl flag? That does not work for me.

In jupyter

This is how we create a cell that will render itself:

%%manim -v WARNING --progress_bar None CreateCircle

class CreateCircle(Scene):
    def construct(self):
        circle = Circle()  # create a circle
        circle.set_fill(PINK, opacity=0.5)  # set the color and transparency  # show the circle on screen

The -v WARNING and --progress_bar None are to keep output minimalist.

It is somewhat hard to find documentation for this features by browsing, but it exists under ManimMagic, although there it punts lots of stuff to the manim command line.

Misc tips

Tip tips

Misfeature: Arrow is a thing, but the tip of teh arrow does not inherit the z_index of the parent. Checking TipableVMobject we find the correct mitigation is

arrow = Arrow(
arrow.z_index = 10
## tip does not inherit z_index
arrow.get_tip().z_index = 10

Fade out everything
    *[FadeOut(mob)for mob in self.mobjects]


OK, but how do we actually create a video with helpful text etc? People do not often post full examples. Here is one, by Act of Learning.

Quick and dirty presentation by screen capture

Painstakingly editing a video in code is very hi-fi, but also tedious and I am happy to throw away some fidelity in order to get my presentations done.

One quick hack to improve the quality of inference is to use a screen capture tool to record the video as it is being rendered. I use quicktime on macos because that is easy, but there are many alternatives on all OSes; in particular there are fancy video routers which will do live compositing.

To make that fluid there need to be something to play back and pause the video animation; this goes much nicer if there are no annoying “pause” and “play” icons on the screen.

Pro-tip: VLC has a mode without such icons, which are called “on screen display”. They can be disabled in the advanced preferences: see How to disable the pause and play on screen icons.

That done, a screen capture of the important bit of the video playing window is a reasonably seamless way to show off the animation, and it is easy to pause and resume the animation as needed. The resulting video might occasionally be paused in the wrong moment and will have some silly resolution (811 pixels high on min machine) but TBH my years of training is in machine learning not in video production, so they are going to have to pay someone if they want something better.

Voiceover mode

A recent feature tries to make the timing of the animation smoother by easing synchronising a script and a recorded or synthesized voice inside the animation.

I personally am bad at writing scripts, and bad at following scripts, and I usually speak off the cuff, so this does not seem to help me.

Interactive mode

OpenGL mode is supposedly interactive:

Adding a line: self.interactive_embed() within your scene allows you to interact with the scene directly via an IPython shell

However, OpenGL mode does not work for me.

In VS Code

There is an extension apparently for live previewing manim animations. It doesn’t work for me; for one it seems to use PowerShell, somehow, but then give an error about a missing /bin/sh. What shell/OS am I even supposed to be using?


Many manim-like packages have been inspired by manim.

  • cubecubed

    Manim, but for node/javascript

  • Reanimate

    Manim, but for Haskell

  • Manim Web

    Manim, but for the web via dart. Claims to generate interactive graphs.

No comments yet. Why not leave one?

GitHub-flavored Markdown & a sane subset of HTML is supported.