Amazing Math Visuals

great YouTube maths channel is 3Brown1Blue. A distinctive feature of the videos is the visuals, which you can replicate — as long as you’ve got some spare time to get the Python library Manim (written by the channel’s author Grant Sanderson) to work.

Yes, you could simulate a pandemic with Manim (screenshot from 3Brown1Blue YoutTube video).

To get Manim to work is not something I say lightly and you may experience a mild anger reaction after an update Manim breaks something that was working well before. Having said that, we can only be grateful for this extraordinary open-source tool (which you could contribute to its development).

My recommendation is patience and to stick to these tips:

  1. Start with a new virtual environment. I’ve managed to set-up Manim in Windows and macOS using conda.
  2. Check any of these resources for installing the system-wide and Python dependencies it needs (and gain inspiration on how to get most of Manim): Repperium Science, Talking Physics, or Manim GitHub itself.
  3. LaTeX is only needed if you intend to show visuals with text or equations, and MikTex has been my choice for both Windows and macOS installs.
  4. Clone or ZIP download the Manim GitHub repository (and if you need an older version, check how to download a specific commit from GitHub repository here).
  5. If using version control tools, be extra careful if you plan to keep your local version of Manim up-to-date with the Manim GitHub repository.

Sooner or later you’ll get it working, don’t give up!

To test that Manim is working correctly, if using Conda (highly recommended) then open Anaconda prompt in Windows or terminal in macOS, activate the environment where you’ve installed the dependencies, navigate to where you’ve cloned or unzipped Manim’s repository and run one of the pre-defined examples (e.g. SquareToCircle will produce a short clip of a square that transforms to a circle). If successful, you’ll have created your first Manim animation!

Activating my ‘manim’ conda environment and navigating to my ‘manim’ local folder in terminal MacOS.

Now it’s time to have some maths fun. For your projects, I’d recommend creating a folder (I called mine ‘myAnimations’) inside Manim’s folder structure. The following script will animate two simple functions in a graph.

Notice that the basic structure of this (and pretty much every) example can be summarised as:

  • Create a class (I called it Example) that inherits methods from one of the jam-packed Manim parent classes (e.g. GraphScene).
  • Define a construct method with the animations.

Run the example script and a new mp4 file will be added to the media folder. Success!

Running with Manim in terminal MacOS. Output file from running

I hope that you found this article useful and that next time you think of ways to animate maths, Manim comes to mind.


Leave a Comment