Graphs & event-ready clips

From static graphs to short, polished clips for events like the ODE–Integration Bee, mini-seminars, and course projects. This page gives concrete patterns you can adapt.

The main Manim Lab shows a compact learning path. This page slows down the “graphs & events” part so that you can see full examples and small variations in one place.

Modules on this page

P1 • Static graphs with axes

The simplest graph scenes show a function on a pair of axes and maybe a highlighted point or region. This pattern already works well for analysis and calculus courses.

📈 A first graph scene Template

from manim import *

class SimpleGraph(Scene):
    def construct(self):
        axes = Axes(
            x_range=[-2, 2, 1],
            y_range=[-1, 4, 1],
            x_length=6,
            y_length=3.5,
            tips=False,
        ).to_edge(DOWN).shift(UP * 0.3)

        labels = axes.get_axis_labels(x_label="x", y_label="y")

        graph = axes.plot(lambda x: x**2, color=BLUE)
        graph_label = MathTex("y = x^2").next_to(axes, UP, buff=0.4)

        self.play(Create(axes), Write(labels))
        self.play(Create(graph))
        self.play(FadeIn(graph_label))
        self.wait(2)
  • Axes defines the numerical ranges and visual size.
  • plot takes a Python function and draws it over the x-range.
  • Labels and titles are just Text / MathTex positioned relative to the axes.
Exercise P1.1 – Compare two functions
  • • Use the same axes, but plot both y = x^2 and y = x^3 with different colours.
  • • Fade them in one after another.
  • • Add labels for each curve at the top.

P2 • Parameter changes & moving dots

To show how a graph changes with a parameter, you can use a ValueTracker and continuously update the graph or a dot.

🧮 Family of graphs with a slider

from manim import *

class ParameterFamily(Scene):
    def construct(self):
        axes = Axes(
            x_range=[-2, 2, 1],
            y_range=[-1, 5, 1],
            x_length=6,
            y_length=3.5,
            tips=False,
        ).to_edge(DOWN).shift(UP * 0.3)

        k_tracker = ValueTracker(1)

        def graph_func(x):
            k = k_tracker.get_value()
            return k * x**2

        graph = always_redraw(
            lambda: axes.plot(graph_func, color=BLUE)
        )

        label = always_redraw(
            lambda: MathTex("y = k x^2", ",\\ k = ", f"{k_tracker.get_value():.1f}")
                    .scale(0.8)
                    .to_edge(UP)
        )

        self.play(Create(axes))
        self.play(FadeIn(graph), FadeIn(label))
        self.wait(0.5)

        self.play(k_tracker.animate.set_value(3), run_time=3)
        self.wait(1)
  • ValueTracker stores a numeric value that can change over time.
  • always_redraw recomputes an object every frame using the latest value.
  • This pattern is ideal for classroom-style “watch the parameter move” explanations.

🔴 Dot moving along a curve

class DotOnGraph(Scene):
    def construct(self):
        axes = Axes(
            x_range=[-2, 2, 1],
            y_range=[-1, 4, 1],
            x_length=6,
            y_length=3.5,
        ).to_edge(DOWN).shift(UP * 0.3)

        graph = axes.plot(lambda x: x**2, color=BLUE)
        dot = Dot(color=RED)

        t_tracker = ValueTracker(-2)

        def update_dot(dot):
            t = t_tracker.get_value()
            dot.move_to(axes.c2p(t, t**2))
            return dot

        dot.add_updater(update_dot)

        self.play(Create(axes), Create(graph))
        self.add(dot)
        self.play(t_tracker.animate.set_value(2), run_time=4)
        self.wait(1)
  • The dot’s position is updated at each frame using the current parameter value.
  • c2p converts from coordinate space to screen position.
  • This pattern also works nicely for visualising solutions to ODEs or trajectories.
Exercise P2.1 – Animate the slope
  • • Add a small line segment representing the tangent at the moving point.
  • • Use a second ValueTracker or a function for the derivative.

P3 • Event intro clip recipe (ODE–Integration Bee, mini-seminars)

A short clip for an event usually has three parts: a fast hook, a middle where the topic is named, and a calm ending with title and date. You do not need many lines of code to achieve this.

🎬 Template for a 10–20 second intro

from manim import *

class EventIntro(Scene):
    def construct(self):
        # Hook: fast appearing objects
        title = Text("ODE–Integration Bee", weight=BOLD)
        subtitle = Text("NAMSSN UI Chapter", font_size=30)
        subtitle.next_to(title, DOWN, buff=0.3)

        self.play(Write(title), run_time=1.2)
        self.play(FadeIn(subtitle, shift=UP * 0.2), run_time=0.8)
        self.wait(0.6)

        # Middle: simple motion on a formula or graph
        formula = MathTex(r"\\int_0^1 x^n\\,dx = \\frac{1}{n+1}")
        formula.to_edge(DOWN).shift(UP * 0.3)

        self.play(FadeOut(subtitle), title.animate.to_edge(UP))
        self.play(Write(formula))
        self.wait(1)

        # Ending: event details
        details = Text(
            "Preliminaries · Week 6\nFinal round · Week 8",
            font_size=28
        ).next_to(formula, DOWN, buff=0.4)

        self.play(FadeIn(details, shift=UP * 0.2))
        self.wait(2)
  • The hook introduces the event name quickly.
  • The middle shows one symbolic object (a formula or graph).
  • The ending quietly displays time and place information.
Exercise P3.1 – Adapt this for a course project
  • • Replace the event title with a project title (e.g. “Numerical methods project”).
  • • Swap the integral formula for a graph or diagram relevant to the project.
  • • Add your name(s) as a final line under the details.

For an actual event, you can match the colour palette of your posters by editing the text colours and background in the Manim code. That way the poster, slides, and clip all feel like one coherent package.

P4 • Exporting, quality, and aspect ratio

All the examples on this page use the same command-line interface you met earlier. To prepare clips for real use, you mostly need to decide the resolution and quality.

🎞️ Common command patterns

# Quick preview (low quality, opens automatically)
manim my_scene.py EventIntro -pql

# Higher quality for final export
manim my_scene.py EventIntro -pqh

# Specify resolution and file name
manim my_scene.py EventIntro -pqh --resolution 1920,1080 -o "bee_intro.mp4"
  • -p opens the video after rendering; -q controls quality (l low, h high).
  • --resolution lets you set the width and height in pixels.
  • -o chooses the output file name.

📱 Thinking about where the clip will live

  • For a projector or laptop screen, 16:9 (e.g. 1920×1080) is usually best.
  • For phone-first social media, you might want 9:16 (vertical) or a square aspect ratio.
  • You can adjust the Manim frame size via the configuration file or command-line options if needed.
Exercise P4.1 – Produce one “real” clip
  • • Take one of the scenes on this page and decide where it will be used: projector, WhatsApp, or YouTube.
  • • Choose an appropriate resolution and export it with a custom file name.
  • • Share the file with a friend and ask if the text is clear on their device.

When students start producing real clips, mentors can collect a small “best of” set for the Math-art gallery or for integration into future event announcements.