number_line

class janim.items.coordinate.number_line.NumberLine(*args, **kwargs)

Number line

Parameters:

  • x_range:

    Use [min_value, max_value, step] to set the number line’s display range and tick step

    Or use [min_value, max_value], with step defaulting to 1

  • unit_size: Unit length of the number line

  • length: Total length of the number line. When this value is set, unit_size is ignored

  • center: Whether to center the whole thing after creation

Arrow parameters:

  • include_tip: Whether to show arrow, default is False (not shown)

  • tip_config: Additional parameters for the arrow, see also add_tip()

Tick parameters:

  • include_ticks: Whether to show ticks, default is True (shown)

  • tick_size: Tick size

  • longer_tick_multiple: Multiple of tick_size for longer ticks

  • numbers_with_elongated_ticks: Provide a list specifying which numbers have elongated ticks

Number parameters:

  • include_numbers: Whether to show numbers

  • numbers_to_exclude: Numbers to exclude

  • line_to_number_direction: Which direction to place numbers relative to tick points

  • line_to_number_buff: Spacing between numbers and tick points

  • number_places:

    Decimal places for numbers, defaults to automatic determination based on tick step

    Note: For the step of x_range, when automatically determining decimal places, 1 and 1.0 are different. The former keeps ticks as integers, while the latter keeps ticks with one decimal place

  • number_config: Additional parameters for numbers, see also Text

default_tip_config = {'back_width': 0.25, 'body_length': 0.25}

Default properties for arrows

default_number_config = {'font_size': 16}

Default properties for numbers

tip_config_d = {'back_width': 0.25, 'body_length': 0.25}
number_config_d = {'font_size': 16}
property tip: ArrowTip | None
property ticks: Group[Line] | None
property numbers: Group[Text] | None
get_unit_size() float
get_tick_range() ndarray
static compute_tick_range(x_min: float, x_max: float, x_step: float) ndarray
add_ticks(excluding: Iterable[float] | None = None) Group[Line]
get_tick(x: float, size: float | None = None) Line
add_numbers(x_values: Iterable[float] | None = None, excluding: Iterable[float] | None = None, **kwargs) Group[Text]
get_number_item(x: float, direction: ndarray | None = None, buff: float | None = None, **number_config) Text
get_axis_label(label: str | Points, *, alpha: float = 1, direction: Vect = array([1., 1., 0.]), buff=0.25, ensure_on_screen: bool = False, **kwargs) TypstMath | Points

Get the axis label text

If label is a string, it will be parsed as a Typst formula and converted to a TypstMath item

The item will be placed in an appropriate location. By default, it’s next to the axis tip. Specifically controlled by alpha, direction, and buff:

  • alpha controls which point on the axis the item is placed next to. This value represents the percentage position on the axis. For example, the default 1 is the end of the axis, and 0 is the start of the axis

  • direction controls which direction the item is placed relative to the aforementioned point. Default is UR, meaning upper right

  • buff controls the spacing between the item and the aforementioned point

If the axis is relatively long, the axis label might go off-screen. If ensure_on_screen=True is set, the axis label will automatically adjust its position to move within the default screen area

number_to_point(number: float | Iterable[float] | ndarray) ndarray

Pass a number to get the corresponding position on the axis

Can pass:

  • A single number, returns a single coordinate representing the position of this number on the axis. For example, n2p(2) gets the position of 2 on the axis

  • Multiple numbers, returns a set of coordinates representing the positions of these numbers on the axis. For example, n2p([0, 2, 4]) gets the positions of 0, 2, and 4 on the axis respectively

point_to_number(point: ndarray) float

Pass a coordinate to map it onto the axis, returns the numerical value on the axis

n2p(number: float) ndarray

Abbreviation for number_to_point

p2n(point: ndarray) float

Abbreviation for point_to_number

class janim.items.coordinate.number_line.UnitInterval(*args, **kwargs)

Unit interval number line (only the 0~1 segment, subdivided into 10 parts)