3b1b/manim · error · Exception

Need at least one color

Error message

Need at least one color

What it means

Exception('Need at least one color') raised by Mobject.set_submobject_colors_by_gradient (manimlib/mobject/mobject.py:1405). The method builds a color_gradient(colors, len(mobs)) spread across submobjects; with an empty *colors tuple there is nothing to distribute, so it rejects the call rather than silently leaving submobjects untouched.

Source

Thrown at manimlib/mobject/mobject.py:1405

    def get_color(self) -> str:
        return rgb_to_hex(self.data["rgba"][0, :3])

    def get_opacity(self) -> float:
        return float(self.data["rgba"][0, 3])

    def get_opacities(self) -> float:
        return self.data["rgba"][:, 3]

    def set_color_by_gradient(self, *colors: ManimColor) -> Self:
        if self.has_points():
            self.set_color(colors)
        else:
            self.set_submobject_colors_by_gradient(*colors)
        return self

    def set_submobject_colors_by_gradient(self, *colors: ManimColor, interp_by_hsl=False) -> Self:
        if len(colors) == 0:
            raise Exception("Need at least one color")
        elif len(colors) == 1:
            return self.set_color(*colors)

        # mobs = self.family_members_with_points()
        mobs = self.submobjects
        new_colors = color_gradient(colors, len(mobs), interp_by_hsl=interp_by_hsl)

        for mob, color in zip(mobs, new_colors):
            mob.set_color(color)
        return self

    def fade(self, darkness: float = 0.5, recurse: bool = True) -> Self:
        self.set_opacity(1.0 - darkness, recurse=recurse)

    def get_shading(self) -> np.ndarray:
        return self.uniforms["shading"]

    def set_shading(

View on GitHub (pinned to dee01804d4)

Solutions

  1. Pass at least one ManimColor: mob.set_submobject_colors_by_gradient(RED, BLUE)
  2. Validate the palette before splatting: assert colors, 'need >= 1 color'
  3. If you meant a no-op recolor, skip the call when the palette is empty instead of calling with zero args

Example fix

# before
palette = [c for c in theme if c.is_visible()]
group.set_submobject_colors_by_gradient(*palette)  # raises when palette == []

# after
palette = [c for c in theme if c.is_visible()]
if palette:
    group.set_submobject_colors_by_gradient(*palette)
else:
    group.set_color(WHITE)
Defensive patterns

Strategy: validation

Validate before calling

assert len(colors) > 0, "gradient requires at least one color"
mob.set_submobject_colors_by_gradient(*colors)

Prevention

When it happens

Trigger: Calling set_submobject_colors_by_gradient() with no arguments; passing an empty list splat: mob.set_submobject_colors_by_gradient(*[]); VGroup(...).set_color_by_gradient() when a colors variable evaluated to empty (also routes here when the group has no points).

Common situations: Theme/palette code that passes a config-driven color list which ended up empty; filtering colors and splatting the result; typo'd variable names leaving colors undefined-but-defaulted to [].

Related errors


AI-assisted analysis of 3b1b/manim@dee01804d4 (2026-08-14). Data as JSON: /api/errors/074553bebc55601d. Report an issue: GitHub.