Axes

Qualified name: manim.mobject.coordinate\_systems.Axes

class Axes(x_range=None, y_range=None, x_length=12, y_length=6, axis_config=None, x_axis_config=None, y_axis_config=None, tips=True, **kwargs)[source]

Bases: manim.mobject.types.vectorized_mobject.VGroup, manim.mobject.coordinate_systems.CoordinateSystem

Creates a set of axes.

Parameters
  • x_range (Optional[Sequence[float]]) – The [x_min, x_max, x_step] values of the x-axis.

  • y_range (Optional[Sequence[float]]) – The [y_min, y_max, y_step] values of the y-axis.

  • x_length (Optional[float]) – The length of the x-axis.

  • y_length (Optional[float]) – The length of the y-axis.

  • axis_config (Optional[dict]) – Arguments to be passed to NumberLine that influences both axes.

  • x_axis_config (Optional[dict]) – Arguments to be passed to NumberLine that influence the x-axis.

  • y_axis_config (Optional[dict]) – Arguments to be passed to NumberLine that influence the y-axis.

  • tips (bool) – Whether or not to include the tips on both axes.

  • kwargs (Any) – Additional arguments to be passed to CoordinateSystem and VGroup.

Methods

coords_to_point

Accepts coordinates from the axes and returns a point with respect to the scene.

get_axes

Gets the axes.

get_line_graph

Draws a line graph.

point_to_coords

Accepts a point from the scene and returns its coordinates with respect to the axes.

Attributes

animate

Used to animate the application of a method.

animation_overrides

depth

The depth of the mobject.

height

The height of the mobject.

width

The width of the mobject.

coords_to_point(*coords)[source]

Accepts coordinates from the axes and returns a point with respect to the scene.

Examples

Example: CoordsToPointExample

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

class CoordsToPointExample(Scene):
    def construct(self):
        ax = Axes().add_coordinates()

        # a dot with respect to the axes
        dot_axes = Dot(ax.coords_to_point(2, 2), color=GREEN)
        lines = ax.get_lines_to_point(ax.c2p(2,2))

        # a dot with respect to the scene
        # the default plane corresponds to the coordinates of the scene.
        plane = NumberPlane()
        dot_scene = Dot((2,2,0), color=RED)

        self.add(plane, dot_scene, ax, dot_axes, lines)
Parameters

coords (Sequence[float]) – The coordinates. Each coord is passed as a separate argument: ax.coords_to_point(1, 2, 3).

Returns

A point with respect to the scene’s coordinate system.

Return type

np.ndarray

get_axes()[source]

Gets the axes.

Returns

A pair of axes.

Return type

VGroup

get_line_graph(x_values, y_values, z_values=None, line_color='#FFFF00', add_vertex_dots=True, vertex_dot_radius=0.08, vertex_dot_style=None, **kwargs)[source]

Draws a line graph.

The graph connects the vertices formed from zipping x_values, y_values and z_values. Also adds Dots at the vertices if add_vertex_dots is set to True.

Parameters
  • x_values (Iterable[float]) – Iterable of values along the x-axis.

  • y_values (Iterable[float]) – Iterable of values along the y-axis.

  • z_values (Optional[Iterable[float]]) – Iterable of values (zeros if z_values is None) along the z-axis.

  • line_color (colour.Color) – Color for the line graph.

  • add_vertex_dots (bool) – Whether or not to add Dot at each vertex.

  • vertex_dot_radius (float) – Radius for the Dot at each vertex.

  • vertex_dot_style (Optional[dict]) – Style arguments to be passed into Dot at each vertex.

  • kwargs – Additional arguments to be passed into VMobject.

Return type

manim.mobject.types.vectorized_mobject.VDict

Examples

Example: LineGraphExample

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

class LineGraphExample(Scene):
    def construct(self):
        plane = NumberPlane(
            x_range = (0, 7),
            y_range = (0, 5),
            x_length = 7,
            axis_config={"include_numbers": True},
        )
        plane.center()
        line_graph = plane.get_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=GOLD_E,
            vertex_dot_style=dict(stroke_width=3,  fill_color=PURPLE),
            stroke_width = 4,
        )
        self.add(plane, line_graph)
Returns

A VDict containing both the line and dots (if specified). The line can be accessed with: line_graph["line_graph"]. The dots can be accessed with: line_graph["vertex_dots"].

Return type

VDict

Parameters
  • x_values (Iterable[float]) –

  • y_values (Iterable[float]) –

  • z_values (Optional[Iterable[float]]) –

  • line_color (colour.Color) –

  • add_vertex_dots (bool) –

  • vertex_dot_radius (float) –

  • vertex_dot_style (Optional[dict]) –

point_to_coords(point)[source]

Accepts a point from the scene and returns its coordinates with respect to the axes.

Examples

Example: PointToCoordsExample

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

class PointToCoordsExample(Scene):
    def construct(self):
        ax = Axes(x_range=[0, 10, 2]).add_coordinates()
        circ = Circle(radius=0.5).shift(UR * 2)

        # get the coordinates of the circle with respect to the axes
        coords = np.around(ax.point_to_coords(circ.get_right()), decimals=2)

        label = (
            Matrix([[coords[0]], [coords[1]]]).scale(0.75).next_to(circ, RIGHT)
        )

        self.add(ax, circ, label, Dot(circ.get_right()))
Parameters

point (Sequence[float]) – The point, i.e. RIGHT or [0, 1, 0].

Returns

The coordinates on the axes, i.e. (4.0, 7.0).

Return type

Tuple[float]