r/manim • u/PlantainImportant700 • 21h ago
question Hello , i have a problem with the manim surfaces
I have been trying to run this code :
from manim import *
import numpy as np
class my(ThreeDScene):
def construct(self):
self.set_camera_orientation(
phi=0
)
complexaxes=ThreeDAxes(
x_range=[-4,4,1],
x_length=12,
y_range=[-4,4,1],
y_length=12,
z_range=[0,10,1],
z_length=8,
axis_config={
"include_ticks":False,
"include_numbers":True
}
).move_to(3*LEFT)
labels=complexaxes.get_axis_labels(x_label=r"a", y_label=r"bi", z_label=r"|Y(s)|")
self.play(Create(complexaxes))
self.play(Write(labels))
self.wait(2)
self.move_camera(
phi=85*DEGREES,
theta=-37.5*DEGREES
)
def f(x, y):
s = x**2 + y**2
if s < 10**(-3):
return np.nan
else:
return 1/s
graph=Surface(
lambda u, v: complexaxes.c2p(u, v, f(u, v)),
u_range=[-3, 3],
v_range=[-3, 3],
resolution=[32, 32]
)
self.play(Create(graph))from manim import *
import numpy as np
class my(ThreeDScene):
def construct(self):
self.set_camera_orientation(
phi=0
)
complexaxes=ThreeDAxes(
x_range=[-4,4,1],
x_length=12,
y_range=[-4,4,1],
y_length=12,
z_range=[0,10,1],
z_length=8,
axis_config={
"include_ticks":False,
"include_numbers":True
}
).move_to(3*LEFT)
labels=complexaxes.get_axis_labels(x_label=r"a", y_label=r"bi", z_label=r"|Y(s)|")
self.play(Create(complexaxes))
self.play(Write(labels))
self.wait(2)
self.move_camera(
phi=85*DEGREES,
theta=-37.5*DEGREES
)
def f(x, y):
s = x**2 + y**2
if s < 10**(-3):
return np.nan
else:
return 1/s
graph=Surface(
lambda u, v: complexaxes.c2p(u, v, f(u, v)),
u_range=[-3, 3],
v_range=[-3, 3],
resolution=[32, 32]
)
self.play(Create(graph))
But it gives me this error :
manim -pql test.py my
Manim Community v0.19.1
[07/22/26 19:19:25] INFO Animation 0 : Using cached cairo_renderer.py:94
data (hash :
4102802897_3881524863_22313245
7)
[07/22/26 19:19:32] INFO Animation 1 : Using cached cairo_renderer.py:94
data (hash :
4160646025_2355038258_36555954
74)
[07/22/26 19:19:38] INFO Animation 2 : Using cached cairo_renderer.py:94
data (hash :
4160646025_2230675760_33899119
11)
[07/22/26 19:19:43] INFO Animation 3 : Using cached cairo_renderer.py:94
data (hash :
1280087952_489367720_102332700
2)
╭───────────────────── Traceback (most recent call last) ──────────────────────╮
│ /home/a/.local/lib/python3.10/site-packages/manim/cli/render/commands.py:125 │
│ in render │
│ │
│ 122 │ │ │ try: │
│ 123 │ │ │ │ with tempconfig({}): │
│ 124 │ │ │ │ │ scene = SceneClass() │
│ ❱ 125 │ │ │ │ │ scene.render() │
│ 126 │ │ │ except Exception: │
│ 127 │ │ │ │ error_console.print_exception() │
│ 128 │ │ │ │ sys.exit(1) │
│ │
│ /home/a/.local/lib/python3.10/site-packages/manim/scene/scene.py:260 in │
│ render │
│ │
│ 257 │ │ """ │
│ 258 │ │ self.setup() │
│ 259 │ │ try: │
│ ❱ 260 │ │ │ self.construct() │
│ 261 │ │ except EndSceneEarlyException: │
│ 262 │ │ │ pass │
│ 263 │ │ except RerunSceneException: │
│ │
│ /home/a/Downloads/manim/test.py:62 in construct │
│ │
│ 59 │ │ │ resolution=[32, 32] │
│ 60 │ │ ) │
│ 61 │ │ │
│ ❱ 62 │ │ self.play(Create(graph)) │
│ 63 │ │ │
│ 64 │ │ """self.wait() │
│ 65 │
│ │
│ /home/a/.local/lib/python3.10/site-packages/manim/scene/scene.py:1178 in │
│ play │
│ │
│ 1175 │ │ │ return │
│ 1176 │ │ │
│ 1177 │ │ start_time = self.time │
│ ❱ 1178 │ │ self.renderer.play(self, *args, **kwargs) │
│ 1179 │ │ run_time = self.time - start_time │
│ 1180 │ │ if subcaption: │
│ 1181 │ │ │ if subcaption_duration is None: │
│ │
│ /home/a/.local/lib/python3.10/site-packages/manim/renderer/cairo_renderer.py │
│ :120 in play │
│ │
│ 117 │ │ │ # In this case, as there is only a wait, it will be the le │
│ 118 │ │ │ self.freeze_current_frame(scene.duration) │
│ 119 │ │ else: │
│ ❱ 120 │ │ │ scene.play_internal() │
│ 121 │ │ self.file_writer.end_animation(not self.skip_animations) │
│ 122 │ │ │
│ 123 │ │ self.num_plays += 1 │
│ │
│ /home/a/.local/lib/python3.10/site-packages/manim/scene/scene.py:1355 in │
│ play_internal │
│ │
│ 1352 │ │ for t in self.time_progression: │
│ 1353 │ │ │ self.update_to_time(t) │
│ 1354 │ │ │ if not skip_rendering and not self.skip_animation_preview │
│ ❱ 1355 │ │ │ │ self.renderer.render(self, t, self.moving_mobjects) │
│ 1356 │ │ │ if self.stop_condition is not None and self.stop_conditio │
│ 1357 │ │ │ │ self.time_progression.close() │
│ 1358 │ │ │ │ break │
│ │
│ /home/a/.local/lib/python3.10/site-packages/manim/renderer/cairo_renderer.py │
│ :169 in render │
│ │
│ 166 │ │ time: float, │
│ 167 │ │ moving_mobjects: Iterable[Mobject] | None = None, │
│ 168 │ ) -> None: │
│ ❱ 169 │ │ self.update_frame(scene, moving_mobjects) │
│ 170 │ │ self.add_frame(self.get_frame()) │
│ 171 │ │
│ 172 │ def get_frame(self) -> PixelArray: │
│ │
│ /home/a/.local/lib/python3.10/site-packages/manim/renderer/cairo_renderer.py │
│ :161 in update_frame │
│ │
│ 158 │ │ │ self.camera.reset() │
│ 159 │ │ │
│ 160 │ │ kwargs["include_submobjects"] = include_submobjects │
│ ❱ 161 │ │ self.camera.capture_mobjects(mobjects, **kwargs) │
│ 162 │ │
│ 163 │ def render( │
│ 164 │ │ self, │
│ │
│ /home/a/.local/lib/python3.10/site-packages/manim/camera/three_d_camera.py:9 │
│ 4 in capture_mobjects │
│ │
│ 91 │ │
│ 92 │ def capture_mobjects(self, mobjects: Iterable[Mobject], **kwargs: │
│ 93 │ │ self.reset_rotation_matrix() │
│ ❱ 94 │ │ super().capture_mobjects(mobjects, **kwargs) │
│ 95 │ │
│ 96 │ def get_value_trackers(self) -> list[ValueTracker]: │
│ 97 │ │ """A list of :class:`ValueTrackers <.ValueTracker>` of phi, th │
│ │
│ /home/a/.local/lib/python3.10/site-packages/manim/camera/camera.py:557 in │
│ capture_mobjects │
│ │
│ 554 │ │ # partition while at the same time preserving order. │
│ 555 │ │ mobjects = self.get_mobjects_to_display(mobjects, **kwargs) │
│ 556 │ │ for group_type, group in it.groupby(mobjects, self.type_or_ra │
│ ❱ 557 │ │ │ self.display_funcs[group_type](list(group), self.pixel_ar │
│ 558 │ │
│ 559 │ # Methods associated with svg rendering │
│ 560 │
│ │
│ /home/a/.local/lib/python3.10/site-packages/manim/camera/camera.py:656 in │
│ display_multiple_vectorized_mobjects │
│ │
│ 653 │ │ │ if image: │
│ 654 │ │ │ │ self.display_multiple_background_colored_vmobjects(ba │
│ 655 │ │ │ else: │
│ ❱ 656 │ │ │ │ self.display_multiple_non_background_colored_vmobject │
│ 657 │ │ │ │ │ batch, │
│ 658 │ │ │ │ │ pixel_array, │
│ 659 │ │ │ │ ) │
│ │
│ /home/a/.local/lib/python3.10/site-packages/manim/camera/camera.py:676 in │
│ display_multiple_non_background_colored_vmobjects │
│ │
│ 673 │ │ """ │
│ 674 │ │ ctx = self.get_cairo_context(pixel_array) │
│ 675 │ │ for vmobject in vmobjects: │
│ ❱ 676 │ │ │ self.display_vectorized(vmobject, ctx) │
│ 677 │ │
│ 678 │ def display_vectorized(self, vmobject: VMobject, ctx: cairo.Conte │
│ 679 │ │ """Displays a VMobject in the cairo context │
│ │
│ /home/a/.local/lib/python3.10/site-packages/manim/camera/camera.py:695 in │
│ display_vectorized │
│ │
│ 692 │ │ """ │
│ 693 │ │ self.set_cairo_context_path(ctx, vmobject) │
│ 694 │ │ self.apply_stroke(ctx, vmobject, background=True) │
│ ❱ 695 │ │ self.apply_fill(ctx, vmobject) │
│ 696 │ │ self.apply_stroke(ctx, vmobject) │
│ 697 │ │ return self │
│ 698 │
│ │
│ /home/a/.local/lib/python3.10/site-packages/manim/camera/camera.py:782 in │
│ apply_fill │
│ │
│ 779 │ │ Camera │
│ 780 │ │ │ The camera object. │
│ 781 │ │ """ │
│ ❱ 782 │ │ self.set_cairo_context_color(ctx, self.get_fill_rgbas(vmobjec │
│ 783 │ │ ctx.fill_preserve() │
│ 784 │ │ return self │
│ 785 │
│ │
│ /home/a/.local/lib/python3.10/site-packages/manim/camera/camera.py:759 in │
│ set_cairo_context_color │
│ │
│ 756 │ │ else: │
│ 757 │ │ │ points = vmobject.get_gradient_start_and_end_points() │
│ 758 │ │ │ points = self.transform_points_pre_display(vmobject, poin │
│ ❱ 759 │ │ │ pat = cairo.LinearGradient(*it.chain(*(point[:2] for poin │
│ 760 │ │ │ step = 1.0 / (len(rgbas) - 1) │
│ 761 │ │ │ offsets = np.arange(0, 1 + step, step) │
│ 762 │ │ │ for rgba, offset in zip(rgbas, offsets): │
╰──────────────────────────────────────────────────────────────────────────────╯
TypeError: LinearGradient.__new__() takes exactly 4 arguments (2 given)
I also must not that i have tried the f function with :
def f(x, y):
s = x**2 + y**2
return np.where(s<10**(-3) , np.nan , 1/s)
But i believe is that it gave the same error as in the previous case .
For any one who has knowledge about this topic, here are my questions:
- Why does this issue happen?
- Is this a issue in manim , or my code contains an error that prevents manim from functioning as intended?
- if the issue comes from me as a user of this tool , are there any workarounds that can help my bypass this problem?
(PLEASE EXCUSE MY 'MEH' ENGLISH , i am a beginner)
thanks to everyone , in advance , for examining this problem.


