Manim (Mathematical Animation)
Manim is the right tool when the explanation is the mathematics: a proof, an algorithm stepping through state, a function transforming, a geometric construction. Its LaTeX typesetting is the reason to use it; its layout system is not.
1. Setup
pip install manim
manim --version
Requirements:
- FFmpeg on PATH (already installed in this workspace).
- LaTeX (TeX Live / MiKTeX) only if you use
MathTex/Tex. Without it,TextandMarkupTextstill work but you lose real math typesetting. - On Windows, MiKTeX's on-the-fly package install must be enabled or the first
MathTexcompile stalls.
Pin the version in a project (manim==0.19.*) — Manim's API has shifted across
minor releases.
2. Scene skeleton
from manim import *
class Pipeline(Scene):
def construct(self):
self.camera.background_color = "#0a0b10"
title = Text("Vector search", font="Inter", weight=BOLD, font_size=56)
title.to_edge(UP, buff=0.6)
q = MathTex(r"q \in \mathbb{R}^{768}").scale(1.1)
dots = VGroup(*[Dot(radius=0.06) for _ in range(6)]).arrange(RIGHT, buff=0.5)
self.play(Write(title), run_time=1.0)
self.play(FadeIn(q, shift=UP * 0.3), run_time=0.8)
self.play(LaggedStart(*[GrowFromCenter(d) for d in dots], lag_ratio=0.12))
self.wait(1.2)
constructis the whole film; there is no timeline object.self.play(...)advances time;self.wait(seconds)holds.- Every animation has
run_time; default is 1s. Be explicit. LaggedStart/AnimationGroup/Successionreplace hand-tuned offsets.
3. The core vocabulary
| Need | Mobject / animation |
|---|---|
| Shapes | Circle, Square, RoundedRectangle, Polygon, Line, Arrow, Dot |
| Text | Text (no LaTeX), MathTex (LaTeX), Tex, MarkupText |
| Grouping | VGroup, Group, .arrange(RIGHT, buff=0.4), .next_to(x, UP) |
| Enter | Create, Write, FadeIn, GrowFromCenter, DrawBorderThenFill |
| Exit | FadeOut, Uncreate, ShrinkToCenter |
| Change | Transform, ReplacementTransform, TransformMatchingTex, ApplyMethod |
| Emphasis | Indicate, Circumscribe, Flash, Wiggle |
| Annotation | Brace, SurroundingRectangle, Arrow, DashedLine |
ReplacementTransform when the target is a new object that should keep
existing; Transform when mutating in place. TransformMatchingTex is the only
clean way to morph equations term by term.
4. Axes, plots, numbers
ax = Axes(
x_range=[0, 6, 1], y_range=[0, 8, 2],
x_length=9, y_length=5,
axis_config={"color": GREY_B, "stroke_width": 2},
tips=True,
).to_edge(DOWN, buff=0.9)
labels = ax.get_axis_labels(x_label="t", y_label="cost")
graph = ax.plot(lambda x: 0.5 * x ** 2, color="#00f0ff", stroke_width=5)
dot = Dot(ax.c2p(0, 0), color="#fcee0a")
tracker = ValueTracker(0)
dot.add_updater(lambda m: m.move_to(ax.c2p(tracker.get_value(),
0.5 * tracker.get_value() ** 2)))
self.play(Create(ax), FadeIn(labels))
self.play(Create(graph), FadeIn(dot), run_time=2)
self.play(tracker.animate.set_value(4), run_time=3, rate_func=smooth)
ax.c2p(x, y)converts data coordinates to scene coordinates. Always use it.ValueTracker+add_updateris how you animate a dependent value.always_redraw(lambda: ...)for labels that must follow a moving object.- Ternary plots, matrices, and tables exist, but they are easier to build as SVG in the main studio unless the math is the point.
5. Camera
class Zoom( MovingCameraScene ):
def construct(self):
circle = Circle(radius=1, color="#9d4edd")
self.play(Create(circle))
self.camera.frame.save_state()
self.play(self.camera.frame.animate.set(width=4).move_to(circle))
self.wait(1)
self.play(Restore(self.camera.frame))
MovingCameraScenefor 2D zoom/pan; animateself.camera.frame.ThreeDScene+set_camera_orientation(phi=..., theta=...)for 3D;begin_ambient_camera_rotation(rate=0.1)for drift.- Keep zooms ≥1.5s and ease with
smooth; a snap zoom reads as a mistake. - Camera moves and object transforms compete for attention — do one at a time.
6. Rendering
manim -qh scene.py Pipeline # 1080p60
manim -qm scene.py Pipeline # 720p30 (fast review)
manim -ql scene.py Pipeline # 480p15 (blocking)
manim -qh -p scene.py Pipeline # render then play
manim -qh -s scene.py Pipeline # last frame only (thumbnail)
manim -qh -t --format webm scene.py Pipeline # transparent alpha
Output lands in media/videos/<file>/<quality>/<Scene>.mp4. Use -o name to
rename, --disable_caching when iterating on a scene that caches badly.
Render discipline:
- Blocking at
-ql, review at-qm, final at-qhonly. - One scene per beat, so a re-render is cheap.
- Keep
media/out of version control except the final MP4s.
7. Compositing into the studio
Manim's strength is the insert, not the whole film. Two patterns:
- Full-frame insert — render 1920×1080 MP4, place it in a Remotion
Series.Sequencewith<OffthreadVideo>, then add titles/captions from the studio on top. - Alpha overlay — render transparent WebM (
-t --format webm), composite over the studio's background. Verify alpha in VLC/Chrome before trusting it;yuva420psupport varies by player.
Match Manim's background to the studio canvas (#0a0b10) and its accent colors
to the palette in explainer-graphics, or the cut will look like two videos.
Audio, captions, and sound design come from the studio pipeline — Manim has no narration or ducking system worth using here.
8. Design rules
- Manim defaults are academic: black background, thin white strokes, LaTeX
blue. Restyle: thicker strokes (
stroke_width=4–6), accent color for the active element, muted grey for context. - One equation per frame. Build it term by term with
TransformMatchingTex. - Annotate in the viewer's language; put the formal notation underneath.
- Minimum on-screen text height ~26px at 1080p (Manim's default
font_size=48is ~0.48 units; check it in the still). - Hold the final state ≥1s. Manim scenes end too fast by default.
- Avoid
self.playchains under 0.4s each; they read as flicker.
9. QC
-
-qlpass reviewed for timing before any-qhrender. - Every
MathTexcompiled (no missing-package fallback boxes). - Text legible at 50% scale; stroke colors survive H.264.
- Final frame held; no abrupt cut to black.
- Insert duration matches the Remotion sequence exactly.
- Alpha overlay verified in a player, not just assumed.