Home

Awesome

jupyter-manim

Build Status codecov MIT License Binder Colab

Integrates 3b1b's ManimCairo (cairo-backend branch) with Jupyter displaying the resulting video when using %%manim cell magic to wrap a scene definition.

WARNING: This library only works for ManimCairo (the cairo-backend branch in 3b1b's version). It does not work for ManimCE (which already has Jupyter support by default) or ManimGL (which does not support Jupyter at all, as of time of writing).

Quick preview

<img src='screenshots/cell_magic_demo.png'>

The code in the example above comes from the excellent manim tutorial.

Run a live demo in your browser by clicking here.

Installation

pip3 install jupyter-manim

Usage

To enable the manim magic please run import jupyter_manim first. Then, you can use the magic as if it was the manim command: your arguments will be passed to manim, exactly as if these were command line options.

For example, to render scene defined with class Shapes(Scene) use

%%manim Shapes
from manimlib.scene.scene import Scene
from manimlib.mobject.geometry import Circle
from manimlib.animation.creation import ShowCreation

class Shapes(Scene):

    def construct(self):
        circle = Circle()
        self.play(ShowCreation(circle))

Since version 1.0, the code is no longer required to be self-contained - jupyter_manim will attempt to export your variables (and imported objects) from the notebook into the manim script.

Most variables can be easily exported, however there are limitations; in short everything which can be pickled can be exported. Additionally, variables whose names start with an underscore will be ommited.

To display manim help and options use:

%%manim -h
pass

The %%manim magic (by default) hides the progress bars as well as other logging messages generated by manim. You can disable this behaviour using --verbose flag

In the latest version of manimlib you can import everything at once using:

from manimlib.imports import *

Video player control options

Compatibility and testing

This package is continuously tested with Python 3.7 on Ubuntu, Mac OS an Windows.

Tests have to be run with ipython, as the magic relies on IPython instance being available:

python3 setup.py install
ipython -m pytest -- --cov=.