manim.mobject.coordinate_systems.CoordinateSystem

class CoordinateSystem(x_range=None, y_range=None, x_length=None, y_length=None, dimension=2)[source]

Bases: object

Abstract class for Axes and NumberPlane

Examples

Example: CoordSysExample

../_images/CoordSysExample-1.png
from manim import *

class CoordSysExample(Scene):
    def construct(self):
        # the location of the ticks depends on the x_range and y_range.
        grid = Axes(
            x_range=[0, 1, 0.05],  # step size determines num_decimal_places.
            y_range=[0, 1, 0.05],
            x_length=9,
            y_length=5.5,
            axis_config={
                "numbers_to_include": np.arange(0, 1 + 0.1, 0.1),
                "number_scale_value": 0.5,
            },
            tips=False,
        )

        # 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, 20 + 0.5, 0.5):
            graphs += grid.get_graph(lambda x: x ** n, color=WHITE)
            graphs += grid.get_graph(
                lambda x: x ** (1 / n), color=WHITE, use_smoothing=False
            )

        # 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 = Title(
            # spaces between braces to prevent SyntaxError
            r"Graphs of $y=x^{ {1}\over{n} }$ and $y=x^n (n=1,2,3,...,20)$",
            include_underline=False,
            scale_factor=0.85,
        )

        self.add(title, graphs, grid, grid_labels)

Methods

add_coordinates

Adds labels to the axes.

angle_of_tangent

Returns the angle to the x-axis of the tangent to the plotted curve at a particular x-value.

c2p

Abbreviation for coords_to_point

coords_to_point

create_label_tex

Checks if the label is a float, int or a str and creates a MathTex label accordingly.

get_T_label

Creates a labelled triangle marker with a vertical line from the x-axis to a curve at a given x-value.

get_area

Returns a VGroup of Riemann rectangles sufficiently small enough to visually approximate the area under the graph passed.

get_axes

get_axis

get_axis_label

Gets the label for an axis.

get_axis_labels

Defines labels for the x_axis and y_axis of the graph.

get_derivative_graph

Returns the curve of the derivative of the passed graph.

get_graph

Generates a curve based on a function.

get_graph_label

Creates a properly positioned label for the passed graph, styled with parameters and an optional dot.

get_horizontal_line

A horizontal line from the y-axis to a given point in the scene.

get_line_from_axis_to_point

Returns a straight line from a given axis to a point in the scene.

get_parametric_curve

get_riemann_rectangles

This method returns the VGroup of the Riemann Rectangles for a particular curve.

get_secant_slope_group

Creates two lines representing dx and df, the labels for dx and df, and

get_vertical_line

A vertical line from the x-axis to a given point in the scene.

get_vertical_lines_to_graph

Obtains multiple lines from the x-axis to the curve.

get_x_axis

get_x_axis_label

get_y_axis

get_y_axis_label

get_z_axis

i2gp

Alias for input_to_graph_point().

input_to_graph_point

Returns the coordinates of the point on the graph corresponding to the input x value.

p2c

Abbreviation for point_to_coords

point_to_coords

slope_of_tangent

Returns the slope of the tangent to the plotted curve at a particular x-value.

add_coordinates(*axes_numbers, **kwargs)[source]

Adds labels to the axes.

axes_numbers

The numbers to be added to the axes. Use None to represent an axis with default labels.

Examples

ax = ThreeDAxes()
x_labels = range(-4, 5)
z_labels = range(-4, 4, 2)
ax.add_coordinates(x_labels, None, z_labels)  # default y labels, custom x & z labels
ax.add_coordinates(x_labels)  # only x labels
Returns

A VGroup of the number mobjects.

Return type

VGroup

Parameters

axes_numbers (Optional[Iterable[float]]) –

angle_of_tangent(x, graph, dx=1e-08)[source]

Returns the angle to the x-axis of the tangent to the plotted curve at a particular x-value.

Parameters
  • x (float) – The x-value at which the tangent must touch the curve.

  • graph (manim.mobject.functions.ParametricFunction) – The ParametricFunction for which to calculate the tangent.

  • dx (float) – The small change in x with which a small change in y will be compared in order to obtain the tangent.

Returns

The angle of the tangent with the x axis.

Return type

float

c2p(*coords)[source]

Abbreviation for coords_to_point

static create_label_tex(label_tex)[source]

Checks if the label is a float, int or a str and creates a MathTex label accordingly.

Parameters

label_tex (The label to be compared against the above types.) –

Returns

The label.

Return type

Mobject

get_T_label(x_val, graph, label=None, label_color='#FFFFFF', triangle_size=0.25, triangle_color='#FFFFFF', line_func=<class 'manim.mobject.geometry.Line'>, line_color='#FFFF00')[source]

Creates a labelled triangle marker with a vertical line from the x-axis to a curve at a given x-value.

Parameters
  • x_val (float) – The position along the curve at which the label, line and triangle will be constructed.

  • graph (manim.mobject.functions.ParametricFunction) – The ParametricFunction for which to construct the label.

  • label (Optional[Union[float, str, manim.mobject.mobject.Mobject]]) – The label of the vertical line and triangle.

  • label_color (colour.Color) – The color of the label.

  • triangle_size (float) – The size of the triangle.

  • triangle_color (colour.Color) – The color of the triangle.

  • line_func (manim.mobject.geometry.Line) – The function used to construct the vertical line.

  • line_color (colour.Color) – The color of the vertical line.

Return type

manim.mobject.types.vectorized_mobject.VGroup

Examples

Example: T_labelExample

../_images/T_labelExample-1.png
from manim import *

class T_labelExample(Scene):
    def construct(self):
        # defines the axes and linear function
        axes = Axes(x_range=[-1, 10], y_range=[-1, 10], x_length=9, y_length=6)
        func = axes.get_graph(lambda x: x, color=BLUE)
        # creates the T_label
        t_label = axes.get_T_label(x_val=4, graph=func, label=Tex("x-value"))
        self.add(axes, func, t_label)
Returns

A VGroup of the label, triangle and vertical line mobjects.

Return type

VGroup

Parameters
get_area(graph, x_range=None, color=['#58C4DD', '#83C167'], opacity=0.3, dx_scaling=1, bounded=None)[source]

Returns a VGroup of Riemann rectangles sufficiently small enough to visually approximate the area under the graph passed.

Parameters
  • graph (manim.mobject.functions.ParametricFunction) – The graph/curve for which the area needs to be gotten.

  • x_range (Optional[Sequence[float]]) – The range of the minimum and maximum x-values of the area. x_range = [x_min, x_max].

  • color (Union[colour.Color, Iterable[colour.Color]]) – The color of the area. Creates a gradient if a list of colors is provided.

  • opacity (float) – The opacity of the area.

  • bounded (Optional[manim.mobject.functions.ParametricFunction]) – If a secondary graph is specified, encloses the area between the two curves.

  • dx_scaling (float) – The factor by which the dx value is scaled.

Returns

The VGroup containing the Riemann Rectangles.

Return type

VGroup

get_axis_label(label, axis, edge, direction, buff=0.1)[source]

Gets the label for an axis.

Parameters
  • label (Union[float, str, manim.mobject.mobject.Mobject]) – The label. Can be any mobject or int/float/str to be used with MathTex

  • axis (manim.mobject.mobject.Mobject) – The axis to which the label will be added.

  • edge (Sequence[float]) – The edge of the axes to which the label will be added. RIGHT adds to the right side of the axis

  • direction (Sequence[float]) – Allows for further positioning of the label.

  • buff (float) – The distance of the label from the line.

Returns

The positioned label along the given axis.

Return type

Mobject

get_axis_labels(x_label='x', y_label='y')[source]

Defines labels for the x_axis and y_axis of the graph.

Parameters
Returns

A Vgroup of the labels for the x_axis and y_axis.

Return type

VGroup

See also

get_x_axis_label, get_y_axis_label

get_derivative_graph(graph, color='#83C167', **kwargs)[source]

Returns the curve of the derivative of the passed graph.

Parameters
Returns

The curve of the derivative.

Return type

ParametricFunction

get_graph(function, x_range=None, **kwargs)[source]

Generates a curve based on a function.

Parameters
  • function (Callable[[float], float]) – The function used to construct the ParametricFunction.

  • x_range (Optional[Sequence[float]]) – The range of the curve along the axes. x_range = [x_min, x_max].

  • kwargs – Additional parameters to be passed to ParametricFunction.

Returns

The plotted curve.

Return type

ParametricFunction

get_graph_label(graph, label='f(x)', x_val=None, direction=array([1., 0., 0.]), buff=0.25, color=None, dot=False, dot_config=None)[source]

Creates a properly positioned label for the passed graph, styled with parameters and an optional dot.

Parameters
  • graph (manim.mobject.functions.ParametricFunction) – The curve of the function plotted.

  • label (Union[float, str, manim.mobject.mobject.Mobject]) – The label for the function’s curve. Written with MathTex if not specified otherwise.

  • x_val (Optional[float]) – The x_value with which the label should be aligned.

  • direction (Sequence[float]) – The cartesian position, relative to the curve that the label will be at –> LEFT, RIGHT

  • buff (float) – The buffer space between the curve and the label.

  • color (Optional[colour.Color]) – The color of the label.

  • dot (bool) – Adds a dot at the given point on the graph.

  • dot_config (Optional[dict]) – Additional parameters to be passed to Dot.

Returns

The positioned label and Dot, if applicable.

Return type

Mobject

get_horizontal_line(point, **kwargs)[source]

A horizontal line from the y-axis to a given point in the scene.

Parameters
  • point (Sequence[float]) – The point to which the horizontal line will be drawn.

  • kwargs – Additional parameters to be passed to get_line_from_axis_to_point

Returns

A horizontal line from the y-axis to the point.

Return type

Line

get_line_from_axis_to_point(index, point, line_func=<class 'manim.mobject.geometry.DashedLine'>, color='#BBBBBB', stroke_width=2)[source]

Returns a straight line from a given axis to a point in the scene.

Parameters
  • index (int) – Specifies the axis from which to draw the line. 0 = x_axis, 1 = y_axis

  • point (Sequence[float]) – The point to which the line will be drawn.

  • line_func (manim.mobject.geometry.Line) – The function of the Line mobject used to construct the line.

  • color (colour.Color) – The color of the line.

  • stroke_width (float) – The stroke width of the line.

Returns

The line from an axis to a point.

Return type

Line

get_riemann_rectangles(graph, x_range=None, dx=0.1, input_sample_type='left', stroke_width=1, stroke_color='#000000', fill_opacity=1, color=array(['#58C4DD', '#83C167'], dtype='<U7'), show_signed_area=True, bounded_graph=None, blend=False, width_scale_factor=1.001)[source]

This method returns the VGroup of the Riemann Rectangles for a particular curve.

Parameters
  • graph (manim.mobject.functions.ParametricFunction) – The graph whose area will be approximated by Riemann rectangles.

  • x_range (Optional[Sequence[float]]) – The minimum and maximum x-values of the rectangles. x_range = [x_min, x_max].

  • dx (Optional[float]) – The change in x-value that separates each rectangle.

  • input_sample_type (str) – Can be any of "left", "right" or "center". Refers to where the sample point for the height of each Riemann Rectangle will be inside the segments of the partition.

  • stroke_width (float) – The stroke_width of the border of the rectangles.

  • stroke_color (colour.Color) – The color of the border of the rectangle.

  • fill_opacity (float) – The opacity of the rectangles.

  • color (Union[Iterable[colour.Color], colour.Color]) – The colors of the rectangles. Creates a balanced gradient if multiple colors are passed.

  • show_signed_area (bool) – Indicates negative area when the curve dips below the x-axis by inverting its color.

  • blend (bool) – Sets the stroke_color to fill_color, blending the rectangles without clear separation.

  • bounded_graph (Optional[manim.mobject.functions.ParametricFunction]) – If a secondary graph is specified, encloses the area between the two curves.

  • width_scale_factor (float) – The factor by which the width of the rectangles is scaled.

Returns

A VGroup containing the Riemann Rectangles.

Return type

VGroup

get_secant_slope_group(x, graph, dx=None, dx_line_color='#FFFF00', dy_line_color=None, dx_label=None, dy_label=None, include_secant_line=True, secant_line_color='#83C167', secant_line_length=10)[source]
Creates two lines representing dx and df, the labels for dx and df, and

the secant to the curve at a particular x-value.

Parameters
  • x (float) – The x-value at which the secant intersects the graph for the first time.

  • graph (manim.mobject.functions.ParametricFunction) – The curve for which the secant will be found.

  • dx (Optional[float]) – The change in x after which the secant exits.

  • dx_line_color (colour.Color) – The color of the line that indicates the change in x.

  • dy_line_color (Optional[colour.Color]) – The color of the line that indicates the change in y. Defaults to the color of graph.

  • dx_label (Optional[Union[float, str]]) – The label for the dx line.

  • dy_label (Optional[Union[float, str]]) – The label for the dy line.

  • include_secant_line (bool) – Whether or not to include the secant line in the graph, or just have the df and dx lines and labels.

  • secant_line_color (colour.Color) – The color of the secant line.

  • secant_line_length (float) – The length of the secant line.

Returns

A group containing the elements: dx_line, df_line, and if applicable also dx_label, df_label, secant_line.

Return type

VGroup

get_vertical_line(point, **kwargs)[source]

A vertical line from the x-axis to a given point in the scene.

Parameters
  • point (Sequence[float]) – The point to which the vertical line will be drawn.

  • kwargs – Additional parameters to be passed to get_line_from_axis_to_point

Returns

A vertical line from the x-axis to the point.

Return type

Line

get_vertical_lines_to_graph(graph, x_range=None, num_lines=20, **kwargs)[source]

Obtains multiple lines from the x-axis to the curve.

Parameters
  • graph (manim.mobject.functions.ParametricFunction) – The graph on which the line should extend to.

  • x_range (Optional[Sequence[float]]) – A list containing the lower and and upper bounds of the lines -> x_range = [x_min, x_max].

  • num_lines (int) – The number of evenly spaced lines.

Returns

The VGroup of the evenly spaced lines.

Return type

VGroup

i2gp(x, graph)[source]

Alias for input_to_graph_point().

input_to_graph_point(x, graph)[source]

Returns the coordinates of the point on the graph corresponding to the input x value.

Parameters
Returns

The coordinates of the point on the graph corresponding to the x value.

Return type

np.ndarray

p2c(point)[source]

Abbreviation for point_to_coords

slope_of_tangent(x, graph, **kwargs)[source]

Returns the slope of the tangent to the plotted curve at a particular x-value.

Parameters
Returns

The slope of the tangent with the x axis.

Return type

float