跳转至

绘图

影片代码
import manimgx as m


def curve(x: float) -> float:
    return 0.25 * x**2 + 0.5


class PlottingHero(m.Scene):
    def construct(self) -> None:
        axes = m.Axes(x_range=[0, 4, 1], y_range=[0, 5, 1], x_length=8, y_length=5.5)
        axes.add_coordinates()
        graph = axes.plot(curve, color=m.BLUE)
        label = axes.get_graph_label(graph, r"\frac{x^2}{4} + \frac{1}{2}", x_val=3.6)
        rectangles = axes.get_riemann_rectangles(
            graph, x_range=[1, 3], dx=0.25, fill_opacity=0.6
        )
        slope = axes.get_secant_slope_group(
            1.5, graph, dx=1, secant_line_color=m.YELLOW
        )
        self.play(m.Create(axes))
        self.play(m.Create(graph), m.Write(label))
        self.play(
            m.LaggedStart(
                *[m.GrowFromEdge(r, m.DOWN) for r in rectangles], lag_ratio=0.1
            )
        )
        self.play(m.FadeOut(rectangles), m.Create(slope))
        self.wait()

plot 在坐标轴上以轴的坐标系绘制一个关于 x 的 Python 函数的图像:它是一条曲线,一个与其他任何 mobject 一样的 mobject,可供设置样式和制作动画。坐标轴随后生成用以阐释它的内容:其末端的标签、其下方的面积、用于其积分的矩形、某点处的斜率、其导数的图像。

这些方法创建新的 mobject,但不添加任何内容到场景中:你需要自行将它们添加到场景中,或为其制作动画。

图像

plot

代码
import numpy as np

import manimgx as m


class AxesPlotExample(m.Scene):
    def construct(self) -> None:
        axes = m.Axes(x_range=[-4, 4], y_range=[-2, 2], y_length=6)
        sine = axes.plot(np.sin, color=m.BLUE)
        parabola = axes.plot(
            lambda x: x**2 - 1.5,
            x_range=[-1.8, 1.8],
            colorscale=[m.GREEN, m.YELLOW, m.RED],
        )
        self.add(axes)
        self.play(m.Create(sine), m.Create(parabola))

在坐标轴上以坐标轴坐标系绘制函数 y = f(x) 的图像。

函数在 x_range 上采样,采样点平滑连接(参见 ParametricFunction);对数 x 轴上 x 在幂上运行。图像将函数保留为其 underlying_function,供处理图像的方法使用。带 colorscale 时,图像的描边是其值(y 或 x)颜色的从左到右渐变,在 x_range 的每一步处取值(未给出时每 0.01)。

axes.plot(function, x_range=None, use_vectorized=False, colorscale=None, colorscale_axis=1, **kwargs)
function

函数,从 x 到 y,在坐标轴坐标系中。

x_range

图像所跨越的 x 的范围,[x_min, x_max] 或 [x_min, x_max, x_step],函数每 x_step 采样一次;None 表示 x 轴的范围。未给出步长时为 x 轴的十分之一。

use_vectorized

function 是否一次性接收所有 x 值(作为数组);无论如何都会先尝试用数组,若不接受则每个值调用一次。

colorscale

按值给图像上色的颜色:颜色在坐标轴范围内均匀分布,或 (color, value) 对,在之间混合;None 表示图像自身的颜色。

colorscale_axis

色阶所依据的值:1 为 y,0 为 x。

dt

曲线的各段在每处不连续点前多远停止,以曲线参数为单位(默认 1e-8)。

discontinuities

曲线断开的参数值:曲线在这些值之间分段绘制(默认 None:无)。

use_smoothing

采样点是否通过过它们的平滑曲线连接,而非用直线段连接(默认 True)。

color

填充与描边共用的颜色(默认白色);None 表示该类的默认值。

fill_color

填充的颜色;未给出时为 color。多个颜色沿 sheen_direction 构成渐变。

fill_opacity

填充的不透明度,取值从 0 到 1(默认 0:无填充)。

stroke_color

描边的颜色;未给出时为 color。多个颜色构成渐变。

stroke_opacity

描边的不透明度,取值从 0 到 1(默认 1)。

stroke_width

描边的宽度,以场景单位的百分之一计(默认 4;0:无描边)。

background_stroke_color

绘制于填充之后的轮廓颜色(默认黑色)。

background_stroke_opacity

轮廓的不透明度,取值从 0 到 1(默认 1)。

background_stroke_width

轮廓的宽度,以场景单位的百分之一计(默认 0:无)。

sheen_factor

颜色朝 sheen_direction 变亮的程度,取值从 -1 到 1(默认 0); 负值变暗。

sheen_direction

颜色变亮的方向(默认 UL)。

joint_type

描边在路径转折处的连接方式:圆角、斜切或斜接,按二维场景的绘制方式 (参见 LineJointType;默认 AUTO:斜接)。

cap_style

描边在其显示的每一端的端点样式(开放路径的端点、虚线的端点):圆头、平头 或方头,按二维场景的绘制方式(参见 CapStyleType;默认 AUTO:平头)。

shade_in_3d

三维场景的光是否对该 mobject 着色。

material

其表面在三维场景中如何反射场景的光(参见 Material);None:Manim 的着色(默认)。

name

mobject 的名称;未给出时为其类名。

z_index

其在绘制顺序中的位置:索引较高者绘制于较低者之上 (默认 0)。

target

MoveToTarget 将 mobject 移动至的状态。

返回 一个新的 ParametricFunction,未添加到坐标轴。

源码

manimgx\mobjects\plotting.py

def plot(
    self,
    function: Callable[[float], float],
    x_range: Sequence[float] | None = None,
    use_vectorized: bool = False,
    colorscale: Colorscale | None = None,
    colorscale_axis: int = 1,
    **kwargs: Unpack[CurveOptions],
) -> ParametricFunction:
    """在坐标轴上以坐标轴坐标系绘制函数 y = f(x) 的图像。

    函数在 `x_range` 上采样,采样点平滑连接(参见 [ParametricFunction][manimgx.ParametricFunction]);对数 x 轴上 x 在幂上运行。图像将函数保留为其 `underlying_function`,供处理图像的方法使用。带 `colorscale` 时,图像的描边是其值(y 或 x)颜色的从左到右渐变,在 `x_range` 的每一步处取值(未给出时每 0.01)。

    Args:
        function: 函数,从 x 到 y,在坐标轴坐标系中。
        x_range: 图像所跨越的 x 的范围,`[x_min, x_max]` 或
            `[x_min, x_max, x_step]`,函数每 `x_step` 采样一次;None
            表示 x 轴的范围。未给出步长时为 x 轴的十分之一。
        use_vectorized: `function` 是否一次性接收所有 x 值(作为数组);无论如何都会先尝试用数组,若不接受则每个值调用一次。
        colorscale: 按值给图像上色的颜色:颜色在坐标轴范围内均匀分布,或 `(color, value)` 对,在之间混合;None 表示图像自身的颜色。
        colorscale_axis: 色阶所依据的值:1 为 y,0 为 x。
        **kwargs: [曲线关键字][manimgx.mobjects.plotting.CurveOptions]:
            `discontinuities`、`use_smoothing` 和样式关键字。

    Returns:
        一个新的 [ParametricFunction][manimgx.ParametricFunction],未添加到坐标轴。

    Examples:
        ```python
        import numpy as np

        import manimgx as m


        class AxesPlotExample(m.Scene):
            def construct(self) -> None:
                axes = m.Axes(x_range=[-4, 4], y_range=[-2, 2], y_length=6)
                sine = axes.plot(np.sin, color=m.BLUE)
                parabola = axes.plot(
                    lambda x: x**2 - 1.5,
                    x_range=[-1.8, 1.8],
                    colorscale=[m.GREEN, m.YELLOW, m.RED],
                )
                self.add(axes)
                self.play(m.Create(sine), m.Create(parabola))
        ```
    """
    t_range = np.array(self.x_range, dtype=float)
    if x_range is not None:
        t_range[: len(x_range)] = x_range
    if x_range is None or len(x_range) < 3:
        t_range[2] /= self.num_sampled_graph_points_per_tick

    def point(t: float | np.ndarray) -> np.ndarray:
        """图像在 t 处的点——或数组中每个 t 处的点,一次调用映射完成。"""
        if isinstance(t, np.ndarray):
            return self.coords_to_point(t, sample(function, t))
        return self.coords_to_point(t, function(t))

    graph = ParametricFunction(
        point,
        t_range=t_range,
        scaling=self.x_axis.scaling,
        use_vectorized=use_vectorized,
        **kwargs,
    )
    graph.underlying_function = function
    if colorscale:
        resolution = (
            x_range[2] if x_range is not None and len(x_range) == 3 else 0.01
        )
        graph.set_stroke(
            self._colorscale(
                function, colorscale, colorscale_axis, t_range, resolution
            )
        )
        graph.set_sheen_direction(RIGHT)
    return graph

plot_line_graph

代码
import manimgx as m


class AxesPlotLineGraphExample(m.Scene):
    def construct(self) -> None:
        axes = m.Axes(x_range=[0, 7], y_range=[0, 5], y_length=6)
        graph = axes.plot_line_graph(
            x_values=[0, 1.5, 2, 2.8, 4, 6.25],
            y_values=[1, 3, 2.25, 4, 2.5, 1.75],
            line_color=m.ORANGE,
            vertex_dot_radius=0.12,
            vertex_dot_style={"color": m.PURPLE},
            stroke_width=6,
        )
        self.add(axes.add_coordinates())
        self.play(m.Create(graph))

绘制折线图:过由其坐标给出的点的直线段,每个点处有一个点;未设置样式时为亮黄色(PURE_YELLOW),带白色点。空输入产生空图。

axes.plot_line_graph(x_values, y_values, z_values=None, line_color=PURE_YELLOW, add_vertex_dots=True, vertex_dot_radius=DEFAULT_DOT_RADIUS, vertex_dot_style=None, **kwargs)
x_values

点的 x 坐标。

y_values

点的 y 坐标,数量相同。

z_values

点的 z 坐标,在三维坐标轴上;None 表示 0。

line_color

线的颜色,除非关键字给出 color。

add_vertex_dots

是否每个点处有一个点标记。

vertex_dot_radius

点的半径,以场景单位计。

vertex_dot_style

点的 样式关键字;None 表示无。

color

填充与描边共用的颜色(默认白色);None 表示该类的默认值。

fill_color

填充的颜色;未给出时为 color。多个颜色沿 sheen_direction 构成渐变。

fill_opacity

填充的不透明度,取值从 0 到 1(默认 0:无填充)。

stroke_color

描边的颜色;未给出时为 color。多个颜色构成渐变。

stroke_opacity

描边的不透明度,取值从 0 到 1(默认 1)。

stroke_width

描边的宽度,以场景单位的百分之一计(默认 4;0:无描边)。

background_stroke_color

绘制于填充之后的轮廓颜色(默认黑色)。

background_stroke_opacity

轮廓的不透明度,取值从 0 到 1(默认 1)。

background_stroke_width

轮廓的宽度,以场景单位的百分之一计(默认 0:无)。

sheen_factor

颜色朝 sheen_direction 变亮的程度,取值从 -1 到 1(默认 0); 负值变暗。

sheen_direction

颜色变亮的方向(默认 UL)。

joint_type

描边在路径转折处的连接方式:圆角、斜切或斜接,按二维场景的绘制方式 (参见 LineJointType;默认 AUTO:斜接)。

cap_style

描边在其显示的每一端的端点样式(开放路径的端点、虚线的端点):圆头、平头 或方头,按二维场景的绘制方式(参见 CapStyleType;默认 AUTO:平头)。

shade_in_3d

三维场景的光是否对该 mobject 着色。

material

其表面在三维场景中如何反射场景的光(参见 Material);None:Manim 的着色(默认)。

name

mobject 的名称;未给出时为其类名。

z_index

其在绘制顺序中的位置:索引较高者绘制于较低者之上 (默认 0)。

target

MoveToTarget 将 mobject 移动至的状态。

还接受 样式关键字。

返回 一个新的 VDict,未添加到坐标轴,线在 "line_graph" 下,点(在一个组中)在 "vertex_dots" 下。

源码

manimgx\mobjects\plotting.py

def plot_line_graph(
    self,
    x_values: Iterable[float],
    y_values: Iterable[float],
    z_values: Iterable[float] | None = None,
    line_color: ParsableManimColor = PURE_YELLOW,
    add_vertex_dots: bool = True,
    vertex_dot_radius: float = DEFAULT_DOT_RADIUS,
    vertex_dot_style: Style | None = None,
    **kwargs: Unpack[Style],
) -> VDict:
    """绘制折线图:过由其坐标给出的点的直线段,每个点处有一个点;未设置样式时为亮黄色(`PURE_YELLOW`),带白色点。空输入产生空图。

    Args:
        x_values: 点的 x 坐标。
        y_values: 点的 y 坐标,数量相同。
        z_values: 点的 z 坐标,在三维坐标轴上;None 表示 0。
        line_color: 线的颜色,除非关键字给出 `color`。
        add_vertex_dots: 是否每个点处有一个点标记。
        vertex_dot_radius: 点的半径,以场景单位计。
        vertex_dot_style: 点的 [样式关键字][manimgx.drawing.paint.Style];None 表示无。
        **kwargs: 线的 [样式关键字][manimgx.drawing.paint.Style]。

    Returns:
        一个新的 [VDict][manimgx.VDict],未添加到坐标轴,线在 `"line_graph"` 下,点(在一个组中)在 `"vertex_dots"` 下。

    Examples:
        ```python
        import manimgx as m


        class AxesPlotLineGraphExample(m.Scene):
            def construct(self) -> None:
                axes = m.Axes(x_range=[0, 7], y_range=[0, 5], y_length=6)
                graph = axes.plot_line_graph(
                    x_values=[0, 1.5, 2, 2.8, 4, 6.25],
                    y_values=[1, 3, 2.25, 4, 2.5, 1.75],
                    line_color=m.ORANGE,
                    vertex_dot_radius=0.12,
                    vertex_dot_style={"color": m.PURPLE},
                    stroke_width=6,
                )
                self.add(axes.add_coordinates())
                self.play(m.Create(graph))
        ```
    """
    xs, ys = (
        np.array(list(x_values), dtype=float),
        np.array(list(y_values), dtype=float),
    )
    zs = (
        np.zeros(xs.shape)
        if z_values is None
        else np.array(list(z_values), dtype=float)
    )
    line_graph = VDict()
    if kwargs.get("color") is None:  # not given, None too
        kwargs["color"] = line_color
    graph = VMobject(**kwargs)
    vertices = self.coords_to_point(*np.array((xs, ys, zs))).T
    graph.set_points_as_corners(vertices)
    line_graph["line_graph"] = graph
    if add_vertex_dots:
        line_graph["vertex_dots"] = VGroup(
            *(
                Dot(
                    point=vertex.copy(),  # the dot retains its center
                    radius=vertex_dot_radius,
                    **(vertex_dot_style or Style()),
                )
                for vertex in vertices
            )
        )
    return line_graph

plot_polar_graph

代码
import numpy as np

import manimgx as m


class AxesPlotPolarGraphExample(m.Scene):
    def construct(self) -> None:
        plane = m.PolarPlane(radius_max=3, size=7.5)
        rose = plane.plot_polar_graph(
            lambda theta: 3 * np.sin(5 * theta), color=m.ORANGE
        )
        self.add(plane)
        self.play(m.Create(rose), run_time=3)

在坐标轴上以极坐标绘制曲线,r = r_func(θ):对于其范围的每个角度 θ,在原点朝 θ 方向、距离 r_func(θ) 处的点。

axes.plot_polar_graph(r_func, theta_range=None, **kwargs)
r_func

函数,从角度 θ(弧度)到距离 r(坐标轴单位)。

theta_range

θ 的范围,[θ_min, θ_max] 或 [θ_min, θ_max, θ_step],弧度,未给出步长时每 0.01 采样;None 表示一整圈,[0, 2π]。

dt

曲线的各段在每处不连续点前多远停止,以曲线参数为单位(默认 1e-8)。

discontinuities

曲线断开的参数值:曲线在这些值之间分段绘制(默认 None:无)。

use_smoothing

采样点是否通过过它们的平滑曲线连接,而非用直线段连接(默认 True)。

color

填充与描边共用的颜色(默认白色);None 表示该类的默认值。

fill_color

填充的颜色;未给出时为 color。多个颜色沿 sheen_direction 构成渐变。

fill_opacity

填充的不透明度,取值从 0 到 1(默认 0:无填充)。

stroke_color

描边的颜色;未给出时为 color。多个颜色构成渐变。

stroke_opacity

描边的不透明度,取值从 0 到 1(默认 1)。

stroke_width

描边的宽度,以场景单位的百分之一计(默认 4;0:无描边)。

background_stroke_color

绘制于填充之后的轮廓颜色(默认黑色)。

background_stroke_opacity

轮廓的不透明度,取值从 0 到 1(默认 1)。

background_stroke_width

轮廓的宽度,以场景单位的百分之一计(默认 0:无)。

sheen_factor

颜色朝 sheen_direction 变亮的程度,取值从 -1 到 1(默认 0); 负值变暗。

sheen_direction

颜色变亮的方向(默认 UL)。

joint_type

描边在路径转折处的连接方式:圆角、斜切或斜接,按二维场景的绘制方式 (参见 LineJointType;默认 AUTO:斜接)。

cap_style

描边在其显示的每一端的端点样式(开放路径的端点、虚线的端点):圆头、平头 或方头,按二维场景的绘制方式(参见 CapStyleType;默认 AUTO:平头)。

shade_in_3d

三维场景的光是否对该 mobject 着色。

material

其表面在三维场景中如何反射场景的光(参见 Material);None:Manim 的着色(默认)。

name

mobject 的名称;未给出时为其类名。

z_index

其在绘制顺序中的位置:索引较高者绘制于较低者之上 (默认 0)。

target

MoveToTarget 将 mobject 移动至的状态。

返回 一个新的 ParametricFunction,未添加到坐标轴。

源码

manimgx\mobjects\plotting.py

def plot_polar_graph(
    self,
    r_func: Callable[[float], float],
    theta_range: Sequence[float] | None = None,
    **kwargs: Unpack[CurveOptions],
) -> ParametricFunction:
    """在坐标轴上以极坐标绘制曲线,r = r_func(θ):对于其范围的每个角度 θ,在原点朝 θ 方向、距离 `r_func(θ)` 处的点。

    Args:
        r_func: 函数,从角度 θ(弧度)到距离 r(坐标轴单位)。
        theta_range: θ 的范围,`[θ_min, θ_max]` 或 `[θ_min, θ_max, θ_step]`,弧度,未给出步长时每 0.01 采样;None 表示一整圈,[0, 2π]。
        **kwargs: [曲线关键字][manimgx.mobjects.plotting.CurveOptions]:
            `use_smoothing` 和样式关键字。

    Returns:
        一个新的 [ParametricFunction][manimgx.ParametricFunction],未添加到坐标轴。

    Examples:
        ```python
        import numpy as np

        import manimgx as m


        class AxesPlotPolarGraphExample(m.Scene):
            def construct(self) -> None:
                plane = m.PolarPlane(radius_max=3, size=7.5)
                rose = plane.plot_polar_graph(
                    lambda theta: 3 * np.sin(5 * theta), color=m.ORANGE
                )
                self.add(plane)
                self.play(m.Create(rose), run_time=3)
        ```
    """
    theta_range = theta_range if theta_range is not None else [0, 2 * PI]
    return ParametricFunction(
        function=lambda th: self.pr2pt(r_func(th), th),
        t_range=theta_range,
        **kwargs,
    )

plot_implicit_curve

代码
import manimgx as m


class AxesPlotImplicitCurveExample(m.Scene):
    def construct(self) -> None:
        axes = m.Axes(x_range=[-3, 3], y_range=[-3, 3], y_length=7)
        curve = axes.plot_implicit_curve(
            lambda x, y: y**2 - x**3 + 2 * x - 1, color=m.YELLOW
        )
        self.add(axes)
        self.play(m.Create(curve))

在坐标轴上以坐标轴坐标系绘制 x 和 y 的函数为零的曲线,即 func(x, y) = 0:在其范围内寻找。

范围的矩形被四等分,每一部分再四等分,在曲线经过处更精细(参见 ImplicitFunction)。对数坐标轴上,函数接收幂。

axes.plot_implicit_curve(func, min_depth=5, max_quads=1500, **kwargs)
func

x 和 y 的函数,在坐标轴坐标系中。

min_depth

矩形至少被四等分的次数:更多次能找到曲线更小的段。

max_quads

矩形最多可划分的单元格数:更多能更紧密地跟随曲线,但耗时更长。

use_smoothing

曲线是否通过其点平滑连接,而非用直线段绘制(默认 True)。

color

填充与描边共用的颜色(默认白色);None 表示该类的默认值。

fill_color

填充的颜色;未给出时为 color。多个颜色沿 sheen_direction 构成渐变。

fill_opacity

填充的不透明度,取值从 0 到 1(默认 0:无填充)。

stroke_color

描边的颜色;未给出时为 color。多个颜色构成渐变。

stroke_opacity

描边的不透明度,取值从 0 到 1(默认 1)。

stroke_width

描边的宽度,以场景单位的百分之一计(默认 4;0:无描边)。

background_stroke_color

绘制于填充之后的轮廓颜色(默认黑色)。

background_stroke_opacity

轮廓的不透明度,取值从 0 到 1(默认 1)。

background_stroke_width

轮廓的宽度,以场景单位的百分之一计(默认 0:无)。

sheen_factor

颜色朝 sheen_direction 变亮的程度,取值从 -1 到 1(默认 0); 负值变暗。

sheen_direction

颜色变亮的方向(默认 UL)。

joint_type

描边在路径转折处的连接方式:圆角、斜切或斜接,按二维场景的绘制方式 (参见 LineJointType;默认 AUTO:斜接)。

cap_style

描边在其显示的每一端的端点样式(开放路径的端点、虚线的端点):圆头、平头 或方头,按二维场景的绘制方式(参见 CapStyleType;默认 AUTO:平头)。

shade_in_3d

三维场景的光是否对该 mobject 着色。

material

其表面在三维场景中如何反射场景的光(参见 Material);None:Manim 的着色(默认)。

name

mobject 的名称;未给出时为其类名。

z_index

其在绘制顺序中的位置:索引较高者绘制于较低者之上 (默认 0)。

target

MoveToTarget 将 mobject 移动至的状态。

返回 一个新的 ImplicitFunction,未添加到坐标轴。

源码

manimgx\mobjects\plotting.py

def plot_implicit_curve(
    self,
    func: Callable[[float, float], float],
    min_depth: int = 5,
    max_quads: int = 1500,
    **kwargs: Unpack[ImplicitOptions],
) -> ImplicitFunction:
    """在坐标轴上以坐标轴坐标系绘制 x 和 y 的函数为零的曲线,即 `func(x, y) = 0`:在其范围内寻找。

    范围的矩形被四等分,每一部分再四等分,在曲线经过处更精细(参见 [ImplicitFunction][manimgx.ImplicitFunction])。对数坐标轴上,函数接收幂。

    Args:
        func: x 和 y 的函数,在坐标轴坐标系中。
        min_depth: 矩形至少被四等分的次数:更多次能找到曲线更小的段。
        max_quads: 矩形最多可划分的单元格数:更多能更紧密地跟随曲线,但耗时更长。
        **kwargs: [隐式曲线关键字][manimgx.mobjects.plotting.ImplicitOptions]:
            `use_smoothing` 和样式关键字。

    Returns:
        一个新的 [ImplicitFunction][manimgx.ImplicitFunction],未添加到坐标轴。

    Examples:
        ```python
        import manimgx as m


        class AxesPlotImplicitCurveExample(m.Scene):
            def construct(self) -> None:
                axes = m.Axes(x_range=[-3, 3], y_range=[-3, 3], y_length=7)
                curve = axes.plot_implicit_curve(
                    lambda x, y: y**2 - x**3 + 2 * x - 1, color=m.YELLOW
                )
                self.add(axes)
                self.play(m.Create(curve))
        ```
    """
    x_scale = self.get_x_axis().scaling
    y_scale = self.get_y_axis().scaling
    graph = ImplicitFunction(
        func=lambda x, y: func(x_scale.function(x), y_scale.function(y)),
        x_range=self.x_range[:2],
        y_range=self.y_range[:2],
        min_depth=min_depth,
        max_quads=max_quads,
        **kwargs,
    )
    graph.stretch(self.get_x_unit_size(), 0, about_point=ORIGIN).stretch(
        self.get_y_unit_size(), 1, about_point=ORIGIN
    ).shift(self.get_origin())
    return graph

plot_derivative_graph

代码
import manimgx as m


class AxesPlotDerivativeGraphExample(m.Scene):
    def construct(self) -> None:
        axes = m.Axes(x_range=[-3, 3], y_range=[-3, 4], y_length=6.5)
        cubic = axes.plot(lambda x: x**3 / 6 - x, color=m.BLUE)
        derivative = axes.plot_derivative_graph(cubic)
        labels = m.VGroup(
            axes.get_graph_label(cubic, "f(x)", x_val=-1.4, direction=m.UP),
            axes.get_graph_label(derivative, "f'(x)", x_val=2.5),
        )
        self.add(axes, cubic, labels[0])
        self.play(m.Create(derivative), m.FadeIn(labels[1]))

绘制图像的导数:在每个 x 处为其 斜率;未设置样式时为绿色。

axes.plot_derivative_graph(graph, **kwargs)
x_range

图像所跨越的 x 的范围,[x_min, x_max] 或 [x_min, x_max, x_step],函数每 x_step 采样一次(默认 None:x 轴的范围;未给出步长时为 x 轴的十分之一)。

use_vectorized

函数是否一次性接收所有 x 值(作为数组)(默认 False:无论如何都会先尝试用数组,若不接受则每个值调用一次)。

colorscale

按值给图像上色的颜色:颜色在坐标轴范围内均匀分布,或 (color, value) 对,在之间混合(默认 None:图像自身的颜色)。

colorscale_axis

色阶所依据的值:1 为 y,0 为 x(默认 1)。

dt

曲线的各段在每处不连续点前多远停止,以曲线参数为单位(默认 1e-8)。

discontinuities

曲线断开的参数值:曲线在这些值之间分段绘制(默认 None:无)。

use_smoothing

采样点是否通过过它们的平滑曲线连接,而非用直线段连接(默认 True)。

color

填充与描边共用的颜色(默认白色);None 表示该类的默认值。

fill_color

填充的颜色;未给出时为 color。多个颜色沿 sheen_direction 构成渐变。

fill_opacity

填充的不透明度,取值从 0 到 1(默认 0:无填充)。

stroke_color

描边的颜色;未给出时为 color。多个颜色构成渐变。

stroke_opacity

描边的不透明度,取值从 0 到 1(默认 1)。

stroke_width

描边的宽度,以场景单位的百分之一计(默认 4;0:无描边)。

background_stroke_color

绘制于填充之后的轮廓颜色(默认黑色)。

background_stroke_opacity

轮廓的不透明度,取值从 0 到 1(默认 1)。

background_stroke_width

轮廓的宽度,以场景单位的百分之一计(默认 0:无)。

sheen_factor

颜色朝 sheen_direction 变亮的程度,取值从 -1 到 1(默认 0); 负值变暗。

sheen_direction

颜色变亮的方向(默认 UL)。

joint_type

描边在路径转折处的连接方式:圆角、斜切或斜接,按二维场景的绘制方式 (参见 LineJointType;默认 AUTO:斜接)。

cap_style

描边在其显示的每一端的端点样式(开放路径的端点、虚线的端点):圆头、平头 或方头,按二维场景的绘制方式(参见 CapStyleType;默认 AUTO:平头)。

shade_in_3d

三维场景的光是否对该 mobject 着色。

material

其表面在三维场景中如何反射场景的光(参见 Material);None:Manim 的着色(默认)。

name

mobject 的名称;未给出时为其类名。

z_index

其在绘制顺序中的位置:索引较高者绘制于较低者之上 (默认 0)。

target

MoveToTarget 将 mobject 移动至的状态。

返回 一个新的 ParametricFunction,未添加到坐标轴。

源码

manimgx\mobjects\plotting.py

def plot_derivative_graph(
    self, graph: ParametricFunction, **kwargs: Unpack[PlotOptions]
) -> ParametricFunction:
    """绘制图像的导数:在每个 x 处为其 [斜率][manimgx.Axes.slope_of_tangent];未设置样式时为绿色。

    Args:
        **kwargs: [绘图关键字][manimgx.mobjects.plotting.PlotOptions]:
            `x_range`、`color`、…。

    Returns:
        一个新的 [ParametricFunction][manimgx.ParametricFunction],未添加到坐标轴。

    Examples:
        ```python
        import manimgx as m


        class AxesPlotDerivativeGraphExample(m.Scene):
            def construct(self) -> None:
                axes = m.Axes(x_range=[-3, 3], y_range=[-3, 4], y_length=6.5)
                cubic = axes.plot(lambda x: x**3 / 6 - x, color=m.BLUE)
                derivative = axes.plot_derivative_graph(cubic)
                labels = m.VGroup(
                    axes.get_graph_label(cubic, "f(x)", x_val=-1.4, direction=m.UP),
                    axes.get_graph_label(derivative, "f'(x)", x_val=2.5),
                )
                self.add(axes, cubic, labels[0])
                self.play(m.Create(derivative), m.FadeIn(labels[1]))
        ```
    """
    if kwargs.get("color") is None:  # not given, None too
        kwargs["color"] = GREEN
    return self.plot(lambda x: self.slope_of_tangent(x, graph), **kwargs)

plot_antiderivative_graph

代码
import manimgx as m


class AxesPlotAntiderivativeGraphExample(m.Scene):
    def construct(self) -> None:
        axes = m.Axes(x_range=[-3, 3], y_range=[-3, 3], y_length=6.5)
        graph = axes.plot(lambda x: (x**2 - 2) / 3, color=m.RED)
        antiderivative = axes.plot_antiderivative_graph(
            graph, y_intercept=1, color=m.BLUE
        )
        self.add(axes, graph)
        self.play(m.Create(antiderivative))

绘制图像的一个原函数:在每个 x 处为图像从 0 到 x 的积分,加上 y_intercept。

每个值是图像在从 0 到 x 的 samples 个点处值的梯形和。

axes.plot_antiderivative_graph(graph, y_intercept=0, samples=50, **kwargs)
y_intercept

原函数在 0 处的值。

samples

每个积分所求和的图像值个数。

x_range

图像所跨越的 x 的范围,[x_min, x_max] 或 [x_min, x_max, x_step],函数每 x_step 采样一次(默认 None:x 轴的范围;未给出步长时为 x 轴的十分之一)。

use_vectorized

函数是否一次性接收所有 x 值(作为数组)(默认 False:无论如何都会先尝试用数组,若不接受则每个值调用一次)。

colorscale

按值给图像上色的颜色:颜色在坐标轴范围内均匀分布,或 (color, value) 对,在之间混合(默认 None:图像自身的颜色)。

colorscale_axis

色阶所依据的值:1 为 y,0 为 x(默认 1)。

dt

曲线的各段在每处不连续点前多远停止,以曲线参数为单位(默认 1e-8)。

discontinuities

曲线断开的参数值:曲线在这些值之间分段绘制(默认 None:无)。

use_smoothing

采样点是否通过过它们的平滑曲线连接,而非用直线段连接(默认 True)。

color

填充与描边共用的颜色(默认白色);None 表示该类的默认值。

fill_color

填充的颜色;未给出时为 color。多个颜色沿 sheen_direction 构成渐变。

fill_opacity

填充的不透明度,取值从 0 到 1(默认 0:无填充)。

stroke_color

描边的颜色;未给出时为 color。多个颜色构成渐变。

stroke_opacity

描边的不透明度,取值从 0 到 1(默认 1)。

stroke_width

描边的宽度,以场景单位的百分之一计(默认 4;0:无描边)。

background_stroke_color

绘制于填充之后的轮廓颜色(默认黑色)。

background_stroke_opacity

轮廓的不透明度,取值从 0 到 1(默认 1)。

background_stroke_width

轮廓的宽度,以场景单位的百分之一计(默认 0:无)。

sheen_factor

颜色朝 sheen_direction 变亮的程度,取值从 -1 到 1(默认 0); 负值变暗。

sheen_direction

颜色变亮的方向(默认 UL)。

joint_type

描边在路径转折处的连接方式:圆角、斜切或斜接,按二维场景的绘制方式 (参见 LineJointType;默认 AUTO:斜接)。

cap_style

描边在其显示的每一端的端点样式(开放路径的端点、虚线的端点):圆头、平头 或方头,按二维场景的绘制方式(参见 CapStyleType;默认 AUTO:平头)。

shade_in_3d

三维场景的光是否对该 mobject 着色。

material

其表面在三维场景中如何反射场景的光(参见 Material);None:Manim 的着色(默认)。

name

mobject 的名称;未给出时为其类名。

z_index

其在绘制顺序中的位置:索引较高者绘制于较低者之上 (默认 0)。

target

MoveToTarget 将 mobject 移动至的状态。

返回 一个新的 ParametricFunction,未添加到坐标轴。

源码

manimgx\mobjects\plotting.py

def plot_antiderivative_graph(
    self,
    graph: ParametricFunction,
    y_intercept: float = 0,
    samples: int = 50,
    **kwargs: Unpack[PlotOptions],
) -> ParametricFunction:
    """绘制图像的一个原函数:在每个 x 处为图像从 0 到 x 的积分,加上 `y_intercept`。

    每个值是图像在从 0 到 x 的 `samples` 个点处值的梯形和。

    Args:
        y_intercept: 原函数在 0 处的值。
        samples: 每个积分所求和的图像值个数。
        **kwargs: [绘图关键字][manimgx.mobjects.plotting.PlotOptions]:
            `x_range`、`color`、…。

    Returns:
        一个新的 [ParametricFunction][manimgx.ParametricFunction],未添加到坐标轴。

    Examples:
        ```python
        import manimgx as m


        class AxesPlotAntiderivativeGraphExample(m.Scene):
            def construct(self) -> None:
                axes = m.Axes(x_range=[-3, 3], y_range=[-3, 3], y_length=6.5)
                graph = axes.plot(lambda x: (x**2 - 2) / 3, color=m.RED)
                antiderivative = axes.plot_antiderivative_graph(
                    graph, y_intercept=1, color=m.BLUE
                )
                self.add(axes, graph)
                self.play(m.Create(antiderivative))
        ```
    """
    axis = 1 if kwargs.get("use_vectorized", False) else 0
    f_vec = np.vectorize(
        graph.underlying_function
        or (lambda x: self.input_to_graph_coords(x, graph)[1])
    )

    def antideriv(x: float) -> float:
        x_vals = np.linspace(0, x, samples, axis=axis)
        return float(np.trapezoid(f_vec(x_vals), x_vals) + y_intercept)

    return self.plot(antideriv, **kwargs)

图像上的点

input_to_graph_point

AxesInputToGraphPointExample
代码
import numpy as np

import manimgx as m


class AxesInputToGraphPointExample(m.Scene):
    def construct(self) -> None:
        axes = m.Axes(x_range=[0, 7], y_range=[-1.5, 1.5, 0.5])
        curve = axes.plot(np.cos, color=m.BLUE)
        dots = m.VGroup(
            *(m.Dot(axes.i2gp(x, curve), radius=0.12) for x in range(7))
        )
        self.add(axes, curve, dots.set_color(m.YELLOW))

在输入处找图像的点:plot 的图像在 x 处;其他曲线在其参数的某个值处。

i2gp 是其简写名。输入可以超出图像的末端:该点为其函数在所绘部分之外的值。

axes.input_to_graph_point(x, graph)
x

输入:图像的 x,在坐标轴坐标系中。

graph

图像或曲线。

返回 点,在场景坐标系中。

源码

manimgx\mobjects\plotting.py

def input_to_graph_point(self, x: float, graph: ParametricFunction) -> Point3D:
    """在输入处找图像的点:[plot][manimgx.Axes.plot] 的图像在 x 处;其他曲线在其参数的某个值处。

    `i2gp` 是其简写名。输入可以超出图像的末端:该点为其函数在所绘部分之外的值。

    Args:
        x: 输入:图像的 x,在坐标轴坐标系中。
        graph: 图像或曲线。

    Returns:
        点,在场景坐标系中。

    Examples:
        ```python
        import numpy as np

        import manimgx as m


        class AxesInputToGraphPointExample(m.Scene):
            def construct(self) -> None:
                axes = m.Axes(x_range=[0, 7], y_range=[-1.5, 1.5, 0.5])
                curve = axes.plot(np.cos, color=m.BLUE)
                dots = m.VGroup(
                    *(m.Dot(axes.i2gp(x, curve), radius=0.12) for x in range(7))
                )
                self.add(axes, curve, dots.set_color(m.YELLOW))
        ```
    """
    return graph.function(x)

i2gp

input_to_graph_point 的简写名。

input_to_graph_coords

找图像在输入处的点的坐标:plot 的图像为 (x, f(x));其他曲线为其参数某值处的点的坐标。

axes.input_to_graph_coords(x, graph)
x

输入:图像的 x。

graph

图像或曲线。

返回 点的坐标,(x, y)。

源码

manimgx\mobjects\plotting.py

def input_to_graph_coords(
    self, x: float, graph: ParametricFunction
) -> tuple[float, float]:
    """找图像在输入处的点的坐标:[plot][manimgx.Axes.plot] 的图像为 (x, f(x));其他曲线为其参数某值处的点的坐标。

    Args:
        x: 输入:图像的 x。
        graph: 图像或曲线。

    Returns:
        点的坐标,(x, y)。
    """
    if (
        graph.underlying_function is None
    ):  # a curve, not a graph of y(x): its point's coordinates
        coords = self.point_to_coords(graph.function(x))
        return float(coords[0]), float(coords[1])
    return (x, graph.underlying_function(x))

get_graph_label

AxesGetGraphLabelExample
代码
import numpy as np

import manimgx as m


class AxesGetGraphLabelExample(m.Scene):
    def construct(self) -> None:
        axes = m.Axes(x_range=[-4, 4], y_range=[-2, 4], x_length=11)
        parabola = axes.plot(lambda x: x**2 / 4, color=m.BLUE)
        sine = axes.plot(np.sin, color=m.YELLOW)
        parabola_label = axes.get_graph_label(parabola, "x^2 / 4")
        sine_label = axes.get_graph_label(
            sine, r"\sin x", x_val=m.PI / 2, direction=m.UP, dot=True
        )
        self.add(axes, parabola, sine, parabola_label, sine_label)

为图像制作标签,在其某个点旁:采用图像的颜色,除非给出其他颜色。

字符串或数字用坐标轴的 label_constructor 排版(默认按数学排版,用 MathTex);mobject 按原样使用,并重新着色。标签放在图像在 x_val 处的点旁,朝 direction 方向,然后若在屏幕外则移回屏幕上。未给出 x_val 时,该点为 x 轴范围内一百个点中最右侧的、位于画框顶部下方的点。

axes.get_graph_label(graph, label='f(x)', x_val=None, direction=RIGHT, buff=MED_SMALL_BUFF, color=None, dot=False, dot_config=None)
label

标签:字符串或数字,按数学排版,或 mobject。

x_val

标签所放的点的 x;None 表示屏幕上最右侧的。

direction

标签从该点放置的方向。

buff

点与标签之间的间距,以场景单位计。

color

标签的颜色;None 表示图像的。

dot

是否有一个点标记该点,作为标签的一部分。

dot_config

点的 样式关键字;None 表示无。

返回 标签,未添加到坐标轴。

源码

manimgx\mobjects\plotting.py

def get_graph_label(
    self,
    graph: ParametricFunction,
    label: Label = "f(x)",
    x_val: float | None = None,
    direction: Vector3DLike = RIGHT,
    buff: float = MED_SMALL_BUFF,
    color: ParsableManimColor | None = None,
    dot: bool = False,
    dot_config: Style | None = None,
) -> Mobject:
    r"""为图像制作标签,在其某个点旁:采用图像的颜色,除非给出其他颜色。

    字符串或数字用坐标轴的 `label_constructor` 排版(默认按数学排版,用 [MathTex][manimgx.MathTex]);mobject 按原样使用,并重新着色。标签放在图像在 `x_val` 处的点旁,朝 `direction` 方向,然后若在屏幕外则移回屏幕上。未给出 `x_val` 时,该点为 x 轴范围内一百个点中最右侧的、位于画框顶部下方的点。

    Args:
        label: 标签:字符串或数字,按数学排版,或 mobject。
        x_val: 标签所放的点的 x;None 表示屏幕上最右侧的。
        direction: 标签从该点放置的方向。
        buff: 点与标签之间的间距,以场景单位计。
        color: 标签的颜色;None 表示图像的。
        dot: 是否有一个点标记该点,作为标签的一部分。
        dot_config: 点的 [样式关键字][manimgx.drawing.paint.Style];None 表示无。

    Returns:
        标签,未添加到坐标轴。

    Examples:
        ```python
        import numpy as np

        import manimgx as m


        class AxesGetGraphLabelExample(m.Scene):
            def construct(self) -> None:
                axes = m.Axes(x_range=[-4, 4], y_range=[-2, 4], x_length=11)
                parabola = axes.plot(lambda x: x**2 / 4, color=m.BLUE)
                sine = axes.plot(np.sin, color=m.YELLOW)
                parabola_label = axes.get_graph_label(parabola, "x^2 / 4")
                sine_label = axes.get_graph_label(
                    sine, r"\sin x", x_val=m.PI / 2, direction=m.UP, dot=True
                )
                self.add(axes, parabola, sine, parabola_label, sine_label)
        ```
    """
    label_object: Mobject = self.x_axis._create_label_tex(label).set_color(
        graph.get_color() if color is None else color
    )
    if x_val is None:  # the rightmost point of the graph that is on screen
        xs = np.linspace(self.x_range[1], self.x_range[0], 100)
        points = (self.input_to_graph_point(x, graph) for x in xs)
        point = next(
            (p for p in points if p[1] < config["frame_y_radius"]),
            self.input_to_graph_point(xs[-1], graph),
        )
    else:
        point = self.input_to_graph_point(x_val, graph)
    label_object.next_to(point, direction, buff=buff)
    label_object.shift_onto_screen()
    if dot:
        label_object.add(Dot(point=point, **(dot_config or Style())))
    return label_object

get_T_label

代码
import numpy as np

import manimgx as m


class AxesGetTLabelExample(m.Scene):
    def construct(self) -> None:
        axes = m.Axes(x_range=[0, 10], y_range=[0, 10], y_length=6)
        graph = axes.plot(lambda x: 3 * np.sqrt(x), color=m.BLUE)
        t_label = axes.get_T_label(4, graph, label=m.MathTex("x = 4"))
        self.add(axes, graph)
        self.play(m.FadeIn(t_label))

为某个 x 值制作 T 标签:x 轴下方一个朝上指向该值的小三角形、三角形下方的标签,以及从 x 轴向上到图像的线。

axes.get_T_label(x_val, graph, label=None, label_color=None, triangle_size=MED_SMALL_BUFF, triangle_color=WHITE, line_func=Line, line_color=PURE_YELLOW)
x_val

它标记的 x 值。

graph

线所达到的图像。

label

三角形下方的标签:字符串或数字,按数学排版,或 mobject;None 表示无。

label_color

标签的颜色;None 表示保持原样。

triangle_size

三角形的高度,以场景单位计。

triangle_color

三角形的颜色。

line_func

线的类:Line(实线)、DashedLine、…。

line_color

线的颜色。

返回 标签(若有)、三角形和线的新组;未添加到坐标轴。

源码

manimgx\mobjects\plotting.py

def get_T_label(
    self,
    x_val: float,
    graph: ParametricFunction,
    label: float | str | Mobject | None = None,
    label_color: ParsableManimColor | None = None,
    triangle_size: float = MED_SMALL_BUFF,
    triangle_color: ParsableManimColor | None = WHITE,
    line_func: type[Line] = Line,
    line_color: ParsableManimColor = PURE_YELLOW,
) -> VGroup:
    """为某个 x 值制作 T 标签:x 轴下方一个朝上指向该值的小三角形、三角形下方的标签,以及从 x 轴向上到图像的线。

    Args:
        x_val: 它标记的 x 值。
        graph: 线所达到的图像。
        label: 三角形下方的标签:字符串或数字,按数学排版,或 mobject;None 表示无。
        label_color: 标签的颜色;None 表示保持原样。
        triangle_size: 三角形的高度,以场景单位计。
        triangle_color: 三角形的颜色。
        line_func: 线的类:[Line][manimgx.Line](实线)、[DashedLine][manimgx.DashedLine]、…。
        line_color: 线的颜色。

    Returns:
        标签(若有)、三角形和线的新组;未添加到坐标轴。

    Examples:
        ```python
        import numpy as np

        import manimgx as m


        class AxesGetTLabelExample(m.Scene):
            def construct(self) -> None:
                axes = m.Axes(x_range=[0, 10], y_range=[0, 10], y_length=6)
                graph = axes.plot(lambda x: 3 * np.sqrt(x), color=m.BLUE)
                t_label = axes.get_T_label(4, graph, label=m.MathTex("x = 4"))
                self.add(axes, graph)
                self.play(m.FadeIn(t_label))
        ```
    """
    T_label_group = VGroup()
    triangle = RegularPolygon(n=3, start_angle=np.pi / 2, stroke_width=0).set_fill(
        color=triangle_color, opacity=1
    )
    triangle.height = triangle_size
    triangle.move_to(self.coords_to_point(x_val, 0), UP)
    if label is not None:
        t_label = self.x_axis._create_label_tex(label)
        if label_color is not None:
            t_label.set_color(label_color)
        t_label.next_to(triangle, DOWN)
        T_label_group.add(t_label)
    v_line = self.get_vertical_line(
        self.i2gp(x_val, graph), color=line_color, line_func=line_func
    )
    T_label_group.add(triangle, v_line)
    return T_label_group

get_vertical_lines_to_graph

代码
import numpy as np

import manimgx as m


class AxesGetVerticalLinesToGraphExample(m.Scene):
    def construct(self) -> None:
        axes = m.Axes(x_range=[0, 8], y_range=[-1, 1, 0.5], y_length=5)
        curve = axes.plot(
            lambda x: np.sin(2 * x) * np.exp(-x / 4), color=m.YELLOW
        )
        lines = axes.get_vertical_lines_to_graph(
            curve, x_range=[0.5, 7.5], num_lines=15, color=m.BLUE
        )
        self.add(axes, curve)
        self.play(m.Create(lines))

制作从 x 轴到图像的线,在某 x 范围内均匀分布:虚线,未设置样式时为白色细线。

axes.get_vertical_lines_to_graph(graph, x_range=None, num_lines=20, **kwargs)
x_range

x 的范围,[x_min, x_max]:第一条线在 x_min 处,最后一条在 x_max 处;None 表示 x 轴的范围。

num_lines

线的数量。

line_func

线的类(默认 DashedLine;Line 是实线)。

line_config

线的 虚线关键字,但不包括其颜色和宽度,由 color 和 stroke_width 设置(默认 None:无)。

color

线的颜色(默认 None:白色)。

stroke_width

线的宽度,以场景单位的百分之一计(默认 2)。

返回 线的新组,从左到右;未添加到坐标轴。

源码

manimgx\mobjects\plotting.py

def get_vertical_lines_to_graph(
    self,
    graph: ParametricFunction,
    x_range: Sequence[float] | None = None,
    num_lines: int = 20,
    **kwargs: Unpack[AxisLine],
) -> VGroup:
    """制作从 x 轴到图像的线,在某 x 范围内均匀分布:虚线,未设置样式时为白色细线。

    Args:
        x_range: x 的范围,`[x_min, x_max]`:第一条线在 x_min 处,最后一条在 x_max 处;None 表示 x 轴的范围。
        num_lines: 线的数量。
        **kwargs: [坐标轴线关键字][manimgx.mobjects.plotting.AxisLine]:
            线的类、关键字、`color` 和 `stroke_width`。

    Returns:
        线的新组,从左到右;未添加到坐标轴。

    Examples:
        ```python
        import numpy as np

        import manimgx as m


        class AxesGetVerticalLinesToGraphExample(m.Scene):
            def construct(self) -> None:
                axes = m.Axes(x_range=[0, 8], y_range=[-1, 1, 0.5], y_length=5)
                curve = axes.plot(
                    lambda x: np.sin(2 * x) * np.exp(-x / 4), color=m.YELLOW
                )
                lines = axes.get_vertical_lines_to_graph(
                    curve, x_range=[0.5, 7.5], num_lines=15, color=m.BLUE
                )
                self.add(axes, curve)
                self.play(m.Create(lines))
        ```
    """
    x_range = x_range if x_range is not None else self.x_range
    return VGroup(
        *(
            self.get_vertical_line(self.i2gp(x, graph), **kwargs)
            for x in np.linspace(x_range[0], x_range[1], num_lines)
        )
    )

面积

get_area

AxesGetAreaExample
代码
import manimgx as m


class AxesGetAreaExample(m.Scene):
    def construct(self) -> None:
        axes = m.Axes(x_range=[0, 5], y_range=[0, 6], y_length=6.5)
        curve = axes.plot(lambda x: 5 - (x - 2.5) ** 2 / 2, color=m.BLUE)
        line = axes.plot(lambda x: x / 2, color=m.YELLOW)
        under = axes.get_area(curve, x_range=(0.5, 2))
        between = axes.get_area(
            curve, x_range=(3, 4.5), bounded_graph=line, color=m.RED
        )
        self.add(axes, under, between, curve, line)

制作图像与 x 轴之间、或两个图像之间在某 x 范围内的面积:一个多边形,未设置样式时从蓝到绿且半透明。

面积的边缘跟随图像自身的点,沿 x 轴闭合,或沿 bounded_graph 返回;其填充和轮廓都采用 color 和 opacity。两个范围不相交的图像引发 ValueError。

axes.get_area(graph, x_range=None, color=(BLUE, GREEN), opacity=0.3, bounded_graph=None, **kwargs)
x_range

x 的范围,(x_min, x_max);None 表示图像的。

color

面积的颜色,或渐变颜色。

opacity

面积的不透明度,从 0 到 1。

bounded_graph

面积所达到的第二个图像,而非 x 轴;None 表示 x 轴。仅覆盖两个图像都跨越的范围。

fill_color

填充的颜色;未给出时为 color。多个颜色沿 sheen_direction 构成渐变。

fill_opacity

填充的不透明度,取值从 0 到 1(默认 0:无填充)。

stroke_color

描边的颜色;未给出时为 color。多个颜色构成渐变。

stroke_opacity

描边的不透明度,取值从 0 到 1(默认 1)。

stroke_width

描边的宽度,以场景单位的百分之一计(默认 4;0:无描边)。

background_stroke_color

绘制于填充之后的轮廓颜色(默认黑色)。

background_stroke_opacity

轮廓的不透明度,取值从 0 到 1(默认 1)。

background_stroke_width

轮廓的宽度,以场景单位的百分之一计(默认 0:无)。

sheen_factor

颜色朝 sheen_direction 变亮的程度,取值从 -1 到 1(默认 0); 负值变暗。

sheen_direction

颜色变亮的方向(默认 UL)。

joint_type

描边在路径转折处的连接方式:圆角、斜切或斜接,按二维场景的绘制方式 (参见 LineJointType;默认 AUTO:斜接)。

cap_style

描边在其显示的每一端的端点样式(开放路径的端点、虚线的端点):圆头、平头 或方头,按二维场景的绘制方式(参见 CapStyleType;默认 AUTO:平头)。

shade_in_3d

三维场景的光是否对该 mobject 着色。

material

其表面在三维场景中如何反射场景的光(参见 Material);None:Manim 的着色(默认)。

name

mobject 的名称;未给出时为其类名。

z_index

其在绘制顺序中的位置:索引较高者绘制于较低者之上 (默认 0)。

target

MoveToTarget 将 mobject 移动至的状态。

还接受 样式关键字。

返回 一个新的 Polygon,未添加到坐标轴。

源码

manimgx\mobjects\plotting.py

def get_area(
    self,
    graph: ParametricFunction,
    x_range: Sequence[float] | None = None,
    color: ParsableManimColor | Iterable[ParsableManimColor] = (BLUE, GREEN),
    opacity: float = 0.3,
    bounded_graph: ParametricFunction | None = None,
    **kwargs: Unpack[StyleBase],
) -> Polygon:
    """制作图像与 x 轴之间、或两个图像之间在某 x 范围内的面积:一个多边形,未设置样式时从蓝到绿且半透明。

    面积的边缘跟随图像自身的点,沿 x 轴闭合,或沿 `bounded_graph` 返回;其填充和轮廓都采用 `color` 和 `opacity`。两个范围不相交的图像引发 ValueError。

    Args:
        x_range: x 的范围,`(x_min, x_max)`;None 表示图像的。
        color: 面积的颜色,或渐变颜色。
        opacity: 面积的不透明度,从 0 到 1。
        bounded_graph: 面积所达到的第二个图像,而非 x 轴;None 表示 x 轴。仅覆盖两个图像都跨越的范围。
        **kwargs: 多边形的 [样式关键字][manimgx.drawing.paint.Style],但不包括其颜色和不透明度:`stroke_width`、…。

    Returns:
        一个新的 [Polygon][manimgx.Polygon],未添加到坐标轴。

    Examples:
        ```python
        import manimgx as m


        class AxesGetAreaExample(m.Scene):
            def construct(self) -> None:
                axes = m.Axes(x_range=[0, 5], y_range=[0, 6], y_length=6.5)
                curve = axes.plot(lambda x: 5 - (x - 2.5) ** 2 / 2, color=m.BLUE)
                line = axes.plot(lambda x: x / 2, color=m.YELLOW)
                under = axes.get_area(curve, x_range=(0.5, 2))
                between = axes.get_area(
                    curve, x_range=(3, 4.5), bounded_graph=line, color=m.RED
                )
                self.add(axes, under, between, curve, line)
        ```
    """
    if x_range is None:
        a = graph.t_min
        b = graph.t_max
    else:
        a, b = x_range
    if bounded_graph is not None:
        if bounded_graph.t_min > b:
            raise ValueError(f"Ranges not matching: {bounded_graph.t_min} < {b}")
        if bounded_graph.t_max < a:
            raise ValueError(f"Ranges not matching: {bounded_graph.t_max} > {a}")
        a = max(a, bounded_graph.t_min)
        b = min(b, bounded_graph.t_max)
    if bounded_graph is None:
        points = (
            [self.c2p(a), graph.function(a)]
            + [p for p in graph.points if a <= self.p2c(p)[0] <= b]
            + [graph.function(b), self.c2p(b)]
        )
    else:
        graph_points, bounded_graph_points = (
            [g.function(a)]
            + [p for p in g.points if a <= self.p2c(p)[0] <= b]
            + [g.function(b)]
            for g in (graph, bounded_graph)
        )
        points = graph_points + bounded_graph_points[::-1]
    return Polygon(*points, **kwargs).set_opacity(opacity).set_color(color)

get_riemann_rectangles

代码
import manimgx as m


class AxesGetRiemannRectanglesExample(m.Scene):
    def construct(self) -> None:
        axes = m.Axes(x_range=[-3, 3], y_range=[-2, 4], y_length=6.5)
        graph = axes.plot(lambda x: x**2 / 2 - 1, color=m.YELLOW)
        coarse, fine = (
            axes.get_riemann_rectangles(graph, x_range=[-2.5, 2.5], dx=dx)
            for dx in (0.5, 0.1)
        )
        self.add(axes, coarse, graph)
        self.play(m.Transform(coarse, fine), run_time=2)

为图像制作黎曼矩形:从 x 轴(或第二个图像)到图像,宽 dx,其颜色为渐变;未设置样式时以黑色细线勾边。

矩形从 x_range 的起点处每 dx 开始一个,最后一个在其终点之前。每个从 x 轴——或从 bounded_graph,在其左边缘——升到图像在其左边缘、右边缘或中心处(input_sample_type)。带 show_signed_area 时,图像低于其基线的矩形取其颜色的反色。

axes.get_riemann_rectangles(graph, x_range=None, dx=0.1, input_sample_type='left', stroke_width=1, stroke_color=BLACK, fill_opacity=1, color=(BLUE, GREEN), show_signed_area=True, bounded_graph=None, blend=False, width_scale_factor=1.001)
graph

plot 的图像。

x_range

矩形覆盖的 x 的范围,[x_min, x_max];None 表示图像的(以及两者都有的 bounded_graph 的)。

dx

矩形的宽度,以坐标轴单位计。

input_sample_type

每个矩形与图像相遇的位置:"left"、"right" 或 "center"。

stroke_width

矩形轮廓的宽度,以场景单位的百分之一计。

stroke_color

轮廓的颜色(除非 blend)。

fill_opacity

矩形的不透明度,从 0 到 1。

color

矩形的颜色,或从第一个矩形到最后一个的渐变颜色。

show_signed_area

图像低于其基线的矩形是否取其颜色的反色。

bounded_graph

第二个 plot 的图像,矩形从其升起;None 表示 x 轴。

blend

每个轮廓是否取其矩形的颜色,而非 stroke_color。

width_scale_factor

每个矩形比 dx 宽多少,使相邻矩形无缝相接。

返回 矩形的新组,从左到右;未添加到坐标轴。

源码

manimgx\mobjects\plotting.py

def get_riemann_rectangles(
    self,
    graph: ParametricFunction,
    x_range: Sequence[float] | None = None,
    dx: float = 0.1,
    input_sample_type: str = "left",
    stroke_width: float = 1,
    stroke_color: ParsableManimColor = BLACK,
    fill_opacity: float = 1,
    color: Iterable[ParsableManimColor] | ParsableManimColor = (BLUE, GREEN),
    show_signed_area: bool = True,
    bounded_graph: ParametricFunction | None = None,
    blend: bool = False,
    width_scale_factor: float = 1.001,
) -> VGroup:
    """为图像制作黎曼矩形:从 x 轴(或第二个图像)到图像,宽 `dx`,其颜色为渐变;未设置样式时以黑色细线勾边。

    矩形从 `x_range` 的起点处每 `dx` 开始一个,最后一个在其终点之前。每个从 x 轴——或从 `bounded_graph`,在其左边缘——升到图像在其左边缘、右边缘或中心处(`input_sample_type`)。带 `show_signed_area` 时,图像低于其基线的矩形取其颜色的反色。

    Args:
        graph: [plot][manimgx.Axes.plot] 的图像。
        x_range: 矩形覆盖的 x 的范围,`[x_min, x_max]`;None 表示图像的(以及两者都有的 `bounded_graph` 的)。
        dx: 矩形的宽度,以坐标轴单位计。
        input_sample_type: 每个矩形与图像相遇的位置:`"left"`、`"right"` 或 `"center"`。
        stroke_width: 矩形轮廓的宽度,以场景单位的百分之一计。
        stroke_color: 轮廓的颜色(除非 `blend`)。
        fill_opacity: 矩形的不透明度,从 0 到 1。
        color: 矩形的颜色,或从第一个矩形到最后一个的渐变颜色。
        show_signed_area: 图像低于其基线的矩形是否取其颜色的反色。
        bounded_graph: 第二个 [plot][manimgx.Axes.plot] 的图像,矩形从其升起;None 表示 x 轴。
        blend: 每个轮廓是否取其矩形的颜色,而非 `stroke_color`。
        width_scale_factor: 每个矩形比 `dx` 宽多少,使相邻矩形无缝相接。

    Returns:
        矩形的新组,从左到右;未添加到坐标轴。

    Examples:
        ```python
        import manimgx as m


        class AxesGetRiemannRectanglesExample(m.Scene):
            def construct(self) -> None:
                axes = m.Axes(x_range=[-3, 3], y_range=[-2, 4], y_length=6.5)
                graph = axes.plot(lambda x: x**2 / 2 - 1, color=m.YELLOW)
                coarse, fine = (
                    axes.get_riemann_rectangles(graph, x_range=[-2.5, 2.5], dx=dx)
                    for dx in (0.5, 0.1)
                )
                self.add(axes, coarse, graph)
                self.play(m.Transform(coarse, fine), run_time=2)
        ```
    """
    if x_range is None:
        if bounded_graph is None:
            x_range = [graph.t_min, graph.t_max]
        else:
            x_min = max(graph.t_min, bounded_graph.t_min)
            x_max = min(graph.t_max, bounded_graph.t_max)
            x_range = [x_min, x_max]
    rectangles = VGroup()
    x_range_array = np.arange(x_range[0], x_range[1], dx)
    colors = color_gradient(parse_colors(color), len(x_range_array))
    for x, color_x in zip(x_range_array, colors, strict=True):
        if input_sample_type == "left":
            sample_input = x
        elif input_sample_type == "right":
            sample_input = x + dx
        elif input_sample_type == "center":
            sample_input = x + 0.5 * dx
        else:
            raise ValueError("Invalid input sample type")
        graph_point = self.input_to_graph_point(sample_input, graph)
        if bounded_graph is None or bounded_graph.underlying_function is None:
            y_point = _origin_shift(self.y_range)
        else:
            y_point = bounded_graph.underlying_function(x)
        points = np.array(
            [
                self.coords_to_point(x, y_point),
                self.coords_to_point(x + width_scale_factor * dx, y_point),
                graph_point,
            ]
        )
        low, high = points.min(axis=0), points.max(axis=0)
        rect = Rectangle()
        rect.stretch_to_fit_width(high[0] - low[0])
        rect.stretch_to_fit_height(high[1] - low[1])
        rect.shift((low + high) / 2 - rect.get_center())
        rectangles.add(rect)
        if self.p2c(graph_point)[1] < y_point and show_signed_area:
            color_x = invert_color(color_x)
        if blend:
            stroke_color = color_x
        rect.set_style(
            fill_color=color_x,
            fill_opacity=fill_opacity,
            stroke_color=stroke_color,
            stroke_width=stroke_width,
        )
    return rectangles

斜率

slope_of_tangent

在输入处找图像切线的斜率:其导数 dy/dx,在坐标轴坐标系中。

它是 angle_of_tangent 角度的正切。

axes.slope_of_tangent(x, graph, dx=1e-08)
x

输入:plot 的图像的 x。

dx

取切线的步长,以坐标轴单位计。

源码

manimgx\mobjects\plotting.py

def slope_of_tangent(
    self, x: float, graph: ParametricFunction, dx: float = 1e-08
) -> float:
    """在输入处找图像切线的斜率:其导数 dy/dx,在坐标轴坐标系中。

    它是 [angle_of_tangent][manimgx.Axes.angle_of_tangent] 角度的正切。

    Args:
        x: 输入:[plot][manimgx.Axes.plot] 的图像的 x。
        dx: 取切线的步长,以坐标轴单位计。
    """
    return float(np.tan(self.angle_of_tangent(x, graph, dx)))

angle_of_tangent

在输入处找图像切线的角度,在坐标轴坐标系中。

切线从图像在 x 处的点取到其在 x + dx 处的点。

axes.angle_of_tangent(x, graph, dx=1e-08)
x

输入:plot 的图像的 x。

dx

取切线的步长,以坐标轴单位计。

返回 角度,以弧度计,从 x 轴方向逆时针起,在坐标轴坐标系中测量:而非按绘制时(其中单位不同)。

源码

manimgx\mobjects\plotting.py

def angle_of_tangent(
    self, x: float, graph: ParametricFunction, dx: float = 1e-08
) -> float:
    """在输入处找图像切线的角度,在坐标轴坐标系中。

    切线从图像在 `x` 处的点取到其在 `x + dx` 处的点。

    Args:
        x: 输入:[plot][manimgx.Axes.plot] 的图像的 x。
        dx: 取切线的步长,以坐标轴单位计。

    Returns:
        角度,以弧度计,从 x 轴方向逆时针起,在坐标轴坐标系中测量:而非按绘制时(其中单位不同)。
    """
    p0 = np.array([*self.input_to_graph_coords(x, graph)])
    p1 = np.array([*self.input_to_graph_coords(x + dx, graph)])
    return angle_of_vector(p1 - p0)

get_secant_slope_group

代码
import manimgx as m


class AxesGetSecantSlopeGroupExample(m.Scene):
    def construct(self) -> None:
        axes = m.Axes(x_range=[0, 5], y_range=[0, 7], y_length=6.5)
        graph = axes.plot(lambda x: x**2 / 4, color=m.BLUE)
        secant = axes.get_secant_slope_group(
            2,
            graph,
            dx=2,
            dx_label="dx",
            dy_label="dy",
            secant_line_length=7,
            secant_line_color=m.RED,
        )
        self.add(axes, graph)
        self.play(m.Create(secant))

在图像上制作割线的构造,在其 x 和 x + dx 处的点之间:腿 dx 和 df、它们的标签,以及过两点的割线。

dx 腿从第一个点横跨,df 腿向上(或向下)到第二个点,采用图像的颜色,除非给出其他颜色。标签按数学排版(除非是 mobject),一起缩小以适应其腿(到 dx 腿宽和 df 腿高的 80%),放在 dx 腿下方和 df 腿右侧(负 dx 时在上方和左侧),每个采用其腿的颜色。割线长 secant_line_length,在两点之间居中。

axes.get_secant_slope_group(x, graph, dx=None, dx_line_color=PURE_YELLOW, dy_line_color=None, dx_label=None, dy_label=None, include_secant_line=True, secant_line_color=GREEN, secant_line_length=10)
x

第一个点的输入:其 x。

dx

到第二个点的步长,以坐标轴单位计;None 表示 x 轴范围的十分之一。

dx_line_color

dx 腿的颜色。

dy_line_color

df 腿的颜色;None 表示图像的。

dx_label

dx 腿的标签:字符串、数字或 mobject;None 表示无。

dy_label

df 腿的标签,同上;None 表示无。

include_secant_line

构造是否包含割线。

secant_line_color

割线的颜色。

secant_line_length

割线的长度,以场景单位计。

返回 一个新的 SecantSlopeGroup,未添加到坐标轴:其部分为 dx_line、df_line、dx_label、df_label 和 secant_line。

源码

manimgx\mobjects\plotting.py

def get_secant_slope_group(
    self,
    x: float,
    graph: ParametricFunction,
    dx: float | None = None,
    dx_line_color: ParsableManimColor = PURE_YELLOW,
    dy_line_color: ParsableManimColor | None = None,
    dx_label: Label | None = None,
    dy_label: Label | None = None,
    include_secant_line: bool = True,
    secant_line_color: ParsableManimColor = GREEN,
    secant_line_length: float = 10,
) -> SecantSlopeGroup:
    """在图像上制作割线的构造,在其 `x` 和 `x + dx` 处的点之间:腿 dx 和 df、它们的标签,以及过两点的割线。

    dx 腿从第一个点横跨,df 腿向上(或向下)到第二个点,采用图像的颜色,除非给出其他颜色。标签按数学排版(除非是 mobject),一起缩小以适应其腿(到 dx 腿宽和 df 腿高的 80%),放在 dx 腿下方和 df 腿右侧(负 `dx` 时在上方和左侧),每个采用其腿的颜色。割线长 `secant_line_length`,在两点之间居中。

    Args:
        x: 第一个点的输入:其 x。
        dx: 到第二个点的步长,以坐标轴单位计;None 表示 x 轴范围的十分之一。
        dx_line_color: dx 腿的颜色。
        dy_line_color: df 腿的颜色;None 表示图像的。
        dx_label: dx 腿的标签:字符串、数字或 mobject;None 表示无。
        dy_label: df 腿的标签,同上;None 表示无。
        include_secant_line: 构造是否包含割线。
        secant_line_color: 割线的颜色。
        secant_line_length: 割线的长度,以场景单位计。

    Returns:
        一个新的 [SecantSlopeGroup][manimgx.mobjects.plotting.SecantSlopeGroup],未添加到坐标轴:其部分为 `dx_line`、`df_line`、`dx_label`、`df_label` 和 `secant_line`。

    Examples:
        ```python
        import manimgx as m


        class AxesGetSecantSlopeGroupExample(m.Scene):
            def construct(self) -> None:
                axes = m.Axes(x_range=[0, 5], y_range=[0, 7], y_length=6.5)
                graph = axes.plot(lambda x: x**2 / 4, color=m.BLUE)
                secant = axes.get_secant_slope_group(
                    2,
                    graph,
                    dx=2,
                    dx_label="dx",
                    dy_label="dy",
                    secant_line_length=7,
                    secant_line_color=m.RED,
                )
                self.add(axes, graph)
                self.play(m.Create(secant))
        ```
    """
    group = SecantSlopeGroup()
    dx = dx or float(self.x_range[1] - self.x_range[0]) / 10
    dy_line_color = dy_line_color or graph.get_color()
    p1 = self.input_to_graph_point(x, graph)
    p2 = self.input_to_graph_point(x + dx, graph)
    interim_point = p2[0] * RIGHT + p1[1] * UP
    group.dx_line = Line(p1, interim_point, color=dx_line_color)
    group.df_line = Line(interim_point, p2, color=dy_line_color)
    group.add(group.dx_line, group.df_line)
    labels = VGroup()
    if dx_label is not None:
        group.dx_label = self.x_axis._create_label_tex(dx_label)
        labels.add(group.dx_label)
        group.add(group.dx_label)
    if dy_label is not None:
        group.df_label = self.x_axis._create_label_tex(dy_label)
        labels.add(group.df_label)
        group.add(group.df_label)
    if len(labels) > 0:
        max_width = 0.8 * group.dx_line.width
        max_height = 0.8 * group.df_line.height
        if labels.width > max_width:
            labels.width = max_width
        if labels.height > max_height:
            labels.height = max_height
    if dx_label is not None:
        group.dx_label.next_to(
            group.dx_line, np.sign(dx) * DOWN, buff=group.dx_label.height / 2
        )
        group.dx_label.set_color(group.dx_line.get_color())
    if dy_label is not None:
        group.df_label.next_to(
            group.df_line, np.sign(dx) * RIGHT, buff=group.df_label.height / 2
        )
        group.df_label.set_color(group.df_line.get_color())
    if include_secant_line:
        group.secant_line = Line(p1, p2, color=secant_line_color)
        group.secant_line.scale(secant_line_length / group.secant_line.get_length())
        group.add(group.secant_line)
    return group

SecantSlopeGroup

割线的构造,由 get_secant_slope_group 创建:其 dx 和 df 腿、它们的标签和割线,各按名称。

dx_line

水平腿:从图像的第一个点横跨到第二个点之下(或之上)。

df_line

垂直腿:从 dx_line 的末端到第二个点。

dx_label

水平腿的标签(若有)。

df_label

垂直腿的标签(若有)。

secant_line

割线:过两点的线(若有)。

CurveOptions

曲线如何被采样和平滑,附带样式关键字:plot 及其他曲线的关键字,用于传递它们的方法。

dt

曲线的各段在每处不连续点前多远停止,以曲线参数为单位(默认 1e-8)。

discontinuities

曲线断开的参数值:曲线在这些值之间分段绘制(默认 None:无)。

use_smoothing

采样点是否通过过它们的平滑曲线连接,而非用直线段连接(默认 True)。

color

填充与描边共用的颜色(默认白色);None 表示该类的默认值。

fill_color

填充的颜色;未给出时为 color。多个颜色沿 sheen_direction 构成渐变。

fill_opacity

填充的不透明度,取值从 0 到 1(默认 0:无填充)。

stroke_color

描边的颜色;未给出时为 color。多个颜色构成渐变。

stroke_opacity

描边的不透明度,取值从 0 到 1(默认 1)。

stroke_width

描边的宽度,以场景单位的百分之一计(默认 4;0:无描边)。

background_stroke_color

绘制于填充之后的轮廓颜色(默认黑色)。

background_stroke_opacity

轮廓的不透明度,取值从 0 到 1(默认 1)。

background_stroke_width

轮廓的宽度,以场景单位的百分之一计(默认 0:无)。

sheen_factor

颜色朝 sheen_direction 变亮的程度,取值从 -1 到 1(默认 0); 负值变暗。

sheen_direction

颜色变亮的方向(默认 UL)。

joint_type

描边在路径转折处的连接方式:圆角、斜切或斜接,按二维场景的绘制方式 (参见 LineJointType;默认 AUTO:斜接)。

cap_style

描边在其显示的每一端的端点样式(开放路径的端点、虚线的端点):圆头、平头 或方头,按二维场景的绘制方式(参见 CapStyleType;默认 AUTO:平头)。

shade_in_3d

三维场景的光是否对该 mobject 着色。

material

其表面在三维场景中如何反射场景的光(参见 Material);None:Manim 的着色(默认)。

name

mobject 的名称;未给出时为其类名。

z_index

其在绘制顺序中的位置:索引较高者绘制于较低者之上 (默认 0)。

target

MoveToTarget 将 mobject 移动至的状态。

ImplicitOptions

ImplicitFunction 的平滑处理,附带样式关键字,用于传递它们的方法 (plot_implicit_curve)。

use_smoothing

曲线是否通过其点平滑连接,而非用直线段绘制(默认 True)。

color

填充与描边共用的颜色(默认白色);None 表示该类的默认值。

fill_color

填充的颜色;未给出时为 color。多个颜色沿 sheen_direction 构成渐变。

fill_opacity

填充的不透明度,取值从 0 到 1(默认 0:无填充)。

stroke_color

描边的颜色;未给出时为 color。多个颜色构成渐变。

stroke_opacity

描边的不透明度,取值从 0 到 1(默认 1)。

stroke_width

描边的宽度,以场景单位的百分之一计(默认 4;0:无描边)。

background_stroke_color

绘制于填充之后的轮廓颜色(默认黑色)。

background_stroke_opacity

轮廓的不透明度,取值从 0 到 1(默认 1)。

background_stroke_width

轮廓的宽度,以场景单位的百分之一计(默认 0:无)。

sheen_factor

颜色朝 sheen_direction 变亮的程度,取值从 -1 到 1(默认 0); 负值变暗。

sheen_direction

颜色变亮的方向(默认 UL)。

joint_type

描边在路径转折处的连接方式:圆角、斜切或斜接,按二维场景的绘制方式 (参见 LineJointType;默认 AUTO:斜接)。

cap_style

描边在其显示的每一端的端点样式(开放路径的端点、虚线的端点):圆头、平头 或方头,按二维场景的绘制方式(参见 CapStyleType;默认 AUTO:平头)。

shade_in_3d

三维场景的光是否对该 mobject 着色。

material

其表面在三维场景中如何反射场景的光(参见 Material);None:Manim 的着色(默认)。

name

mobject 的名称;未给出时为其类名。

z_index

其在绘制顺序中的位置:索引较高者绘制于较低者之上 (默认 0)。

target

MoveToTarget 将 mobject 移动至的状态。

use_smoothing

曲线是否通过其点平滑连接,而非用直线段绘制(默认 True)。

PlotOptions

plot 除函数外的关键字,用于传递它们的方法 (plot_derivative_graph、 plot_antiderivative_graph):x 的范围和色阶,附带曲线关键字。

x_range

图像所跨越的 x 的范围,[x_min, x_max] 或 [x_min, x_max, x_step],函数每 x_step 采样一次(默认 None:x 轴的范围;未给出步长时为 x 轴的十分之一)。

use_vectorized

函数是否一次性接收所有 x 值(作为数组)(默认 False:无论如何都会先尝试用数组,若不接受则每个值调用一次)。

colorscale

按值给图像上色的颜色:颜色在坐标轴范围内均匀分布,或 (color, value) 对,在之间混合(默认 None:图像自身的颜色)。

colorscale_axis

色阶所依据的值:1 为 y,0 为 x(默认 1)。

dt

曲线的各段在每处不连续点前多远停止,以曲线参数为单位(默认 1e-8)。

discontinuities

曲线断开的参数值:曲线在这些值之间分段绘制(默认 None:无)。

use_smoothing

采样点是否通过过它们的平滑曲线连接,而非用直线段连接(默认 True)。

color

填充与描边共用的颜色(默认白色);None 表示该类的默认值。

fill_color

填充的颜色;未给出时为 color。多个颜色沿 sheen_direction 构成渐变。

fill_opacity

填充的不透明度,取值从 0 到 1(默认 0:无填充)。

stroke_color

描边的颜色;未给出时为 color。多个颜色构成渐变。

stroke_opacity

描边的不透明度,取值从 0 到 1(默认 1)。

stroke_width

描边的宽度,以场景单位的百分之一计(默认 4;0:无描边)。

background_stroke_color

绘制于填充之后的轮廓颜色(默认黑色)。

background_stroke_opacity

轮廓的不透明度,取值从 0 到 1(默认 1)。

background_stroke_width

轮廓的宽度,以场景单位的百分之一计(默认 0:无)。

sheen_factor

颜色朝 sheen_direction 变亮的程度,取值从 -1 到 1(默认 0); 负值变暗。

sheen_direction

颜色变亮的方向(默认 UL)。

joint_type

描边在路径转折处的连接方式:圆角、斜切或斜接,按二维场景的绘制方式 (参见 LineJointType;默认 AUTO:斜接)。

cap_style

描边在其显示的每一端的端点样式(开放路径的端点、虚线的端点):圆头、平头 或方头,按二维场景的绘制方式(参见 CapStyleType;默认 AUTO:平头)。

shade_in_3d

三维场景的光是否对该 mobject 着色。

material

其表面在三维场景中如何反射场景的光(参见 Material);None:Manim 的着色(默认)。

name

mobject 的名称;未给出时为其类名。

z_index

其在绘制顺序中的位置:索引较高者绘制于较低者之上 (默认 0)。

target

MoveToTarget 将 mobject 移动至的状态。

x_range

图像所跨越的 x 的范围,[x_min, x_max] 或 [x_min, x_max, x_step],函数每 x_step 采样一次(默认 None:x 轴的范围;未给出步长时为 x 轴的十分之一)。

use_vectorized

函数是否一次性接收所有 x 值(作为数组)(默认 False:无论如何都会先尝试用数组,若不接受则每个值调用一次)。

colorscale

按值给图像上色的颜色:颜色在坐标轴范围内均匀分布,或 (color, value) 对,在之间混合(默认 None:图像自身的颜色)。

colorscale_axis

色阶所依据的值:1 为 y,0 为 x(默认 1)。

AxisLine

从坐标轴到点的线的关键字 (get_vertical_line 等):其类、其关键字、其颜色和其宽度。

line_func

线的类(默认 DashedLine;Line 是实线)。

line_config

线的 虚线关键字,但不包括其颜色和宽度,由 color 和 stroke_width 设置(默认 None:无)。

color

线的颜色(默认 None:白色)。

stroke_width

线的宽度,以场景单位的百分之一计(默认 2)。

line_func

线的类(默认 DashedLine;Line 是实线)。

line_config

线的 虚线关键字,但不包括其颜色和宽度,由 color 和 stroke_width 设置(默认 None:无)。

color

线的颜色(默认 None:白色)。

stroke_width

线的宽度,以场景单位的百分之一计(默认 2)。