How to Animate Taylor Series in Manim

Animate a Taylor series in Manim by plotting successive partial sums converging to a function like sin(x), each term bending the polynomial closer.

By Shihab
3 min read

To animate a Taylor series, plot the target function and then draw its partial sums one term at a time, watching each higher-degree polynomial hug the curve over a wider interval. For sin(x)\sin(x), the series is xx33!+x55!x - \frac{x^3}{3!} + \frac{x^5}{5!} - \dots, and the animation makes "more terms = better approximation" visible. Build it in Manim, or generate it from a prompt with QuantumSketch.

The intuition first

A Taylor series approximates a function near a point using a polynomial. Each added term corrects the previous approximation a little further from the center. The visual story is simple and powerful: start with a straight line (xx), and every new term bends the polynomial so it matches the true curve over a longer stretch. Animation turns an intimidating formula into an obvious idea — the polynomial reaching out to grab the curve.

Set up axes and the target

Plot sin(x)\sin(x) as the reference the approximations chase:

from manim import *

class TaylorSine(Scene):
    def construct(self):
        axes = Axes(x_range=[-PI*1.5, PI*1.5], y_range=[-2, 2])
        target = axes.plot(lambda x: np.sin(x), color=BLUE)
        self.play(Create(axes), Create(target))

Animate successive partial sums

Define the Taylor partial sum for sin\sin and Transform each approximation into the next, so the polynomial visibly grows toward the curve:

        import math
        def taylor(x, terms):
            return sum((-1)**k * x**(2*k+1) / math.factorial(2*k+1)
                       for k in range(terms))

        approx = axes.plot(lambda x: taylor(x, 1), color=YELLOW)
        self.play(Create(approx))
        for t in range(2, 6):
            nxt = axes.plot(lambda x: taylor(x, t), color=YELLOW)
            self.play(Transform(approx, nxt), run_time=1)
        self.wait()

Each Transform is one more term; the viewer watches the yellow polynomial wrap around more of the blue sine wave.

Label what's happening

Add a degree counter and the current formula so the math and the picture stay linked. Showing "n=3n = 3" alongside the cubic approximation, then "n=5n = 5" as it improves, ties the symbolic series to its geometric meaning. Pair each step with a one-line narration ("adding the x5x^5 term extends the match past π/2\pi/2") and the lesson lands.

Why animation beats a static plot

A static figure of overlaid polynomials is cluttered and hard to read. Animating one term at a time respects how people learn — one change at a time, with the previous state as context. This is the core of effective math video: isolate a single idea per beat. QuantumSketch automates the whole flow (storyboard, render, narration) from a text prompt; the techniques are open in manim-coding-skill.

Frequently Asked Questions

How do you animate a Taylor series? Plot the target function, then draw each partial sum in sequence, using Transform to morph one approximation into the next as terms are added.

What's a good function to demonstrate Taylor series? sin(x)\sin(x), cos(x)\cos(x), and exe^x are ideal — their series are clean and the convergence is visually striking.

Why does adding terms improve the approximation? Each term cancels more of the error of the previous polynomial, extending the interval where it matches the true function.

Can I generate this without coding Manim? Yes — describe it to QuantumSketch and it produces a narrated Manim animation from the prompt.


Written by Shihab Shahriar Antor — AI Engineer & Founder of Shahriar Labs. Generate calculus animations from a prompt with QuantumSketch; see the Manim patterns in manim-coding-skill. Also building freelm.

Tags:#manim#taylor-series#calculus#math-animation#tutorial
S

Shihab Shahriar

AI Engineer & Founder of Shahriar Labs. Exploring the intersection of design, cognition, and machine learning.