coordinate_systems

class janim.items.coordinate.coordinate_systems.CoordinateSystem(*args, num_sampled_graph_points_per_tick, **kwargs)

Bases: object

Abstract base class for coordinate systems

For concrete implementations, please refer to Axes, ThreeDAxes, and NumberPlane

static create_axis(range: RangeSpecifier, axis_config: dict, length: float | None) NumberLine
abstractmethod get_axes() list[NumberLine]

Get a list composed of NumberLine in each direction

get_origin() ndarray
coords_to_point(*coords: float) ndarray

Pass coordinates to get the corresponding position

For example, c2p(1, 3) gets the position (1,3)

coords_array_to_points(coords_array: VectArray) ndarray

Pass a set of coordinates to get the corresponding set of positions

For example, c2p([[1, 3], [2, 1], [-1, -1]]) gets the corresponding three positions

c2p(*coords: float) ndarray

Abbreviation for coords_to_point()

point_to_coords3d(point: Vect | Iterable[Vect]) ndarray

Pass a position to get the corresponding coordinates (but will be expanded to 3D coordinates; for 2D coordinate systems, the third component represents the distance from the 2D plane)

Can also pass a set of positions to get a corresponding set of coordinates

p2c3d(point: Vect | Iterable[Vect]) ndarray

Abbreviation for point_to_coords3d()

point_to_coords(point: Vect | Iterable[Vect]) ndarray

Pass a position to get the corresponding coordinates

Can also pass a set of positions to get a corresponding set of coordinates

p2c(point: Vect | Iterable[Vect]) ndarray

Abbreviation for point_to_coords()

number_to_point(number: complex | float) ndarray

Pass a complex number to get the corresponding position

n2p(number: complex | float) ndarray

Abbreviation for number_to_point()

point_to_number(point: Vect) complex

Pass a position to get the corresponding complex number

p2n(point: Vect) complex

Abbreviation for point_to_number()

class janim.items.coordinate.coordinate_systems.Axes(x_range: RangeSpecifier = (-8.0, 8.0, 1), y_range: RangeSpecifier = (-4.0, 4.0, 1), *, num_sampled_graph_points_per_tick: int = 5, axis_config: dict = {}, x_axis_config: dict = {}, y_axis_config: dict = {}, x_length: float | None = None, y_length: float | None = None, height: float | None = None, width: float | None = None, unit_size: float = 1.0, **kwargs)

Bases: CoordinateSystem, MarkedItem, NamedGroupMixin

2D Axes

  • num_sampled_graph_points_per_tick:

    Indicates the number of points sampled in each tick segment by the get_graph() method when the sampling step is omitted

  • axis_config:

    Configuration shared by both x and y axes. For available parameters, please refer to NumberLine

  • x_axis_config:

    Configuration for the x-axis. For available parameters, please refer to NumberLine

  • y_axis_config:

    Configuration for the y-axis. For available parameters, please refer to NumberLine

  • x_length:

    When specified, stretches the length of the x-axis to match this value

  • y_length:

    When specified, stretches the length of the y-axis to match this value

  • unit_size:

    Specifies the unit length for x and y coordinates. Ignored if the corresponding *_length is specified

    Note: To specify unit_size for a specific axis, please pass it via the corresponding *_axis_config

default_axis_config = {'numbers_to_exclude': [0]}
default_x_axis_config = {}
default_y_axis_config = {'line_to_number_direction': array([0., 1., 0.])}
axis_config_d = {'numbers_to_exclude': [0]}
x_axis_config_d = {}
y_axis_config_d = {'line_to_number_direction': array([0., 1., 0.])}
property x_axis: NumberLine
property y_axis: NumberLine
get_axes() list[NumberLine]

Get a list composed of NumberLine in each direction

get_graph(function: Callable[[float], float], x_range: RangeSpecifier | None = None, *, bind: bool = True, **kwargs) ParametricCurve

Constructs a function curve based on coordinate axes, using ParametricCurve

  • function: Function used to construct the curve

  • x_range: Domain of the function

    If not specified, the domain of the x-axis is used

    When specified, [x_min, x_max, x_step] can be used, or the sampling step can be omitted as [x_min, x_max]

    If the sampling step is not specified, the axis tick step divided by the item’s num_sampled_graph_points_per_tick is used as the sampling step

  • bind: By default is True, makes the function curve automatically synchronize with transformations applied to the coordinate system, can also synchronize animations. For details, see NumberPlaneExample in API Demonstration

Warning

When bind=True, do not place the function curve and coordinate system in the same Group for coordinate transformations

Because it will cause the transformation effect to be applied twice (once by Group and once by bind=True)

If you need to place them in the same Group, pass bind=False to avoid this situation

get_parametric_curve(function: Callable[[float], Vect], t_range: tuple[float, float, float] = (0, 1, 0.1), *, bind: bool = True, **kwargs)

Constructs a parametric curve based on coordinate axes, i.e., ParametricCurve

  • function: Parametric function that maps values to points on the coordinate system

  • bind: By default is True, makes the parametric curve automatically synchronize with transformations applied to the coordinate system, can also synchronize animations. For details, see NumberPlaneExample in API Demonstration

Warning

When bind=True, do not place the parametric curve and coordinate system in the same Group for coordinate transformations

Because it will cause the transformation effect to be applied twice (once by Group and once by bind=True)

If you need to place them in the same Group, pass bind=False to avoid this situation

get_area(graph: ParametricCurve, x_range: tuple[float, float] | None = None, color: JAnimColor = '#58C4DD', alpha: float = 0.3, stroke_alpha: float | None = None, fill_alpha: float | None = None, bounded_graph: ParametricCurve = None, **kwargs) Polygon

Constructs the region enclosed by graph and the coordinate axes within the x_range interval, represented using Polygon

  • graph: Function curve, see also get_graph()

  • x_range: Minimum and maximum values of the x interval, x_range = [x_min, x_max]

  • bounded_graph: If this parameter is specified, the region enclosed by graph and bounded_graph will be constructed, rather than with the coordinate axes

get_axis_labels(x_label: str | Points = 'x', y_label: str | Points = 'y', x_kwargs: dict = {}, y_kwargs: dict = {}, **kwargs) Group[TypstMath | Points]

For details, see get_axis_label()

If ensure_on_screen=True is set, axis labels will automatically adjust their position to move within the default screen area

get_x_axis_label(label: str | Points = 'x', **kwargs) TypstMath | Points

For details, see get_axis_label()

If ensure_on_screen=True is set, axis labels will automatically adjust their position to move within the default screen area

get_y_axis_label(label: str | Points = 'y', **kwargs) TypstMath | Points

For details, see get_axis_label()

If ensure_on_screen=True is set, axis labels will automatically adjust their position to move within the default screen area

class janim.items.coordinate.coordinate_systems.ThreeDAxes(x_range: RangeSpecifier = (-6, 6, 1), y_range: RangeSpecifier = (-5, 5, 1), z_range: RangeSpecifier = (-4, 4, 1), *, axis_config: dict = {}, z_length: float | None = None, z_axis_config: dict = {}, z_normal: Vect = array([0., 1., 0.]), **kwargs)

Bases: Axes

3D Axes

  • z_normal indicates the orientation of ticks and arrow-tip on the z-axis. Defaults to facing UP

For other available parameters, please refer to and draw analogies from Axes

default_z_axis_config = {}
z_axis_config_d = {}
property z_axis: NumberLine
get_axes() list[NumberLine]

Get a list composed of NumberLine in each direction

get_axis_labels(x_label: str | Points = 'x', y_label: str | Points = 'y', z_label: str | Points = 'z', x_kwargs: dict = {}, y_kwargs: dict = {}, z_kwargs: dict = {}, rotate_xy: bool = True, z_point_up: bool = True, **kwargs) Group[TypstMath | Points]

For details, see get_axis_label()

Additionally, by default rotate_xy=True rotates the x and y axis labels 180 degrees in place to match the perspective of looking at the origin from the positive directions of the x, y, and z axes

Furthermore, directly generated z-axis labels are parallel to the 2D plane. By default point_up=True orients them upright to align with the z-axis direction. Pass point_up=False to disable this behavior

get_z_axis_label(label: str | Points = 'z', point_up: bool = True, **kwargs) TypstMath | Points

For details, see get_axis_label()

Additionally, directly generated axis labels are parallel to the 2D plane. By default point_up=True orients them upright to align with the z-axis direction. Pass point_up=False to disable this behavior

class janim.items.coordinate.coordinate_systems.CmptVPoints_NumberPlaneImpl(*args, **kwargs)

Bases: Cmpt_VPoints

prepare_for_nonlinear_transform(num_inserted_curves: int = 50, *, root_only=False) Self
class janim.items.coordinate.coordinate_systems.NumberPlane(x_range: RangeSpecifier = (-8.0, 8.0, 1), y_range: RangeSpecifier = (-4.0, 4.0, 1), background_line_style: dict = {}, faded_line_style: dict = {}, faded_line_ratio: int = 4, **kwargs)

Bases: Axes

Coordinate Grid

Generally includes:

  • Axes:

    Defaults to white axes, without arrow tips and tick lines

  • Major grid lines

    Default color is BLUE_D. Can be adjusted via background_line_style

  • Minor grid lines:

    • Can be adjusted via faded_line_style

      When faded_line_style is not set, it adopts the same configuration as background_line_style, but with 50% opacity

    • Use faded_line_ratio to adjust the number of minor grid lines within each grid cell

      For example, the default 4 means 4 minor grid lines are evenly distributed between two major grid lines

      Can be set to 1 to reduce density, or set to 0 to disable minor grid lines

For more parameters and methods, please refer to Axes

points
default_background_line_style = {'stroke_color': '#29ABCA', 'stroke_radius': 0.01}
default_axis_config = {'include_ticks': False, 'include_tip': False, 'line_to_number_buff': 0.1, 'line_to_number_direction': array([-1., -1.,  0.]), 'stroke_color': '#FFFFFF', 'stroke_radius': 0.01}
default_y_axis_config = {'line_to_number_direction': array([-1., -1.,  0.]), 'numbers_to_exclude': [0]}
background_line_style_d = {'stroke_color': '#29ABCA', 'stroke_radius': 0.01}
axis_config_d = {'include_ticks': False, 'include_tip': False, 'line_to_number_buff': 0.1, 'line_to_number_direction': array([-1., -1.,  0.]), 'stroke_color': '#FFFFFF', 'stroke_radius': 0.01}
y_axis_config_d = {'line_to_number_direction': array([-1., -1.,  0.]), 'numbers_to_exclude': [0]}
property background_lines: Group[Line]
property faded_lines: Group[Line]
get_lines_parallel_to_axis(axis1: NumberLine, axis2: NumberLine) tuple[Group[Line], Group[Line]]