到目前为止,我们一直在研究表单的功能具有一个自变量和一个因变量。这些函数可以在二维空间中表示,使用两个数值轴,使我们能够用两个数字识别平面中的每个点。我们现在想谈谈三维空间;为了识别三维空间中的每个点,我们需要三个数值。建立这种关联的明显方法是添加一个新轴,垂直于和我们已经明白的轴。例如,我们可以添加第三个轴,即z轴, 与正z轴直接从页面中出来,而负极则zz轴从页面的背面伸出。这在打印页面上很难处理,因此我们通常从一个角度绘制三个轴的视图:
示例1:
from manim import *
class CoordSysExample(Scene):
def construct(self):
grid = Axes(
x_range=[0, 1, 0.1],
y_range=[0, 1, 0.1],
x_length=9,
y_length=5.5,
axis_config={
"numbers_to_include": np.arange(0, 1 + 0.1, 0.1),
"font_size": 24,
},
tips=False,
color=GREEN
)
# Labels for the x-axis and y-axis
y_label = grid.get_y_axis_label("y", edge=LEFT, direction=LEFT, buff=0.4)
x_label = grid.get_x_axis_label("x")
grid_labels = VGroup(x_label, y_label)
graphs = VGroup()
for n in np.arange(1.5, 10.5, 0.5): # Adjusting the range step
graphs += grid.plot(lambda x: x ** n, color=YELLOW)
graphs += grid.plot(lambda x: x ** (1 / n), color=RED_B, use_smoothing=False)
# Create a dashed line for y = x
A12 = DashedLine(start=grid.c2p(0, 0), end=grid.c2p(1, 1), color=WHITE)
self.add(A12)
# Extra lines and labels for point (1,1)
graphs += grid.get_horizontal_line(grid.c2p(1, 1, 0), color=BLUE)
graphs += grid.get_vertical_line(grid.c2p(1, 1, 0), color=BLUE)
graphs += Dot(point=grid.c2p(1, 1, 0), color=YELLOW)
graphs += Tex("(1,1)").scale(0.75).next_to(grid.c2p(1, 1, 0))
# Title of the scene
title = Title(
r"Graphs of $y=x^{ {1}\over{n} }$ and $y=x^n (n=1,2,3,...,10)$",
include_underline=False,
font_size=40,
)
# Display all elements
self.add(title, graphs, grid, grid_labels)
运行结果:
标签:c2p,color,创建,label,graphs,grid,坐标,axis,Manim From: https://blog.csdn.net/qq_45449625/article/details/140854677