3b1b/manim · error · Exception
Invalid input sample type
Error message
Invalid input sample type
What it means
Exception('Invalid input sample type') raised in Axes.get_riemann_rectangles (manimlib/mobject/coordinate_systems.py:395). The input_sample_type keyword controls where each rectangle samples the function height and only accepts exactly 'left', 'right', or 'center'; any other string (or typo/case variant) reaches the else branch.
Source
Thrown at manimlib/mobject/coordinate_systems.py:395
if x_range is None:
x_range = self.x_range[:2]
if dx is None:
dx = self.x_range[2]
if len(x_range) < 3:
x_range = [*x_range, dx]
rects = []
x_range[1] = x_range[1] + dx
xs = np.arange(*x_range)
for x0, x1 in zip(xs, xs[1:]):
if input_sample_type == "left":
sample = x0
elif input_sample_type == "right":
sample = x1
elif input_sample_type == "center":
sample = 0.5 * x0 + 0.5 * x1
else:
raise Exception("Invalid input sample type")
height_vect = self.i2gp(sample, graph) - self.c2p(sample, 0)
rect = Rectangle(
width=self.x_axis.n2p(x1)[0] - self.x_axis.n2p(x0)[0],
height=get_norm(height_vect),
)
rect.positive = height_vect[1] > 0
rect.move_to(self.c2p(x0, 0), DL if rect.positive else UL)
rects.append(rect)
result = VGroup(*rects)
result.set_submobject_colors_by_gradient(*colors)
result.set_style(
stroke_width=stroke_width,
stroke_color=stroke_color,
fill_opacity=fill_opacity,
stroke_behind=stroke_background
)
for rect in result:
if not rect.positive:View on GitHub (pinned to dee01804d4)
Solutions
- Use one of the exact literals: "left", "right", or "center"
- Normalize input before the call: value = value.strip().lower() and validate against {'left','right','center'}
- If a custom sample point is needed, write your own rectangle loop using i2gp instead of relying on input_sample_type
Example fix
# before rects = axes.get_riemann_rectangles(graph, input_sample_type="midpoint") # after rects = axes.get_riemann_rectangles(graph, input_sample_type="center")
Defensive patterns
Strategy: validation
Validate before calling
VALID = {"left", "right", "center"}
sample_type = str(user_input).strip().lower()
assert sample_type in VALID, f"input_sample_type must be one of {VALID}, got {user_input!r}"
rects = axes.get_riemann_rectangles(graph, input_sample_type=sample_type) Type guard
def is_valid_sample_type(value: str) -> bool:
return value in {"left", "right", "center"} Prevention
- Use typing.Literal['left','right','center'] in wrappers to get static checking
- Remember 'center' is the midpoint option; 'midpoint' is not accepted
When it happens
Trigger: Calling get_riemann_rectangles(..., input_sample_type='midpoint'), 'Center', 'LEFT', or any non-literal string; passing a variable whose value drifted from the three allowed literals.
Common situations: Math convention mismatch: users write 'midpoint' or 'middle' instead of 'center'; case-sensitive copies from other libraries (matplotlib's density args); typos in scene config files.
Related errors
- At least 2 mobjects needed for Union.
- At least 2 mobjects needed for Intersection.
- At least 2 mobjects needed for Exclusion.
- Not implemented
- Mobject cannot contain self
AI-assisted analysis of 3b1b/manim@dee01804d4 (2026-08-14).
Data as JSON: /api/errors/3e38bc4c92d96fe5.
Report an issue: GitHub.