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 stepOr use
[min_value, max_value], with step defaulting to 1unit_size: Unit length of the number linelength: Total length of the number line. When this value is set,unit_sizeis ignoredcenter: Whether to center the whole thing after creation
Arrow parameters:
include_tip: Whether to show arrow, default isFalse(not shown)tip_config: Additional parameters for the arrow, see alsoadd_tip()
Tick parameters:
include_ticks: Whether to show ticks, default isTrue(shown)tick_size: Tick sizelonger_tick_multiple: Multiple oftick_sizefor longer ticksnumbers_with_elongated_ticks: Provide a list specifying which numbers have elongated ticks
Number parameters:
include_numbers: Whether to show numbersnumbers_to_exclude: Numbers to excludeline_to_number_direction: Which direction to place numbers relative to tick pointsline_to_number_buff: Spacing between numbers and tick pointsnumber_places:Decimal places for numbers, defaults to automatic determination based on tick step
Note: For the
stepofx_range, when automatically determining decimal places,1and1.0are different. The former keeps ticks as integers, while the latter keeps ticks with one decimal placenumber_config: Additional parameters for numbers, see alsoText
- 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}¶
- get_unit_size() float¶
- get_tick_range() ndarray¶
- static compute_tick_range(x_min: float, x_max: float, x_step: float) ndarray¶
- 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
labelis a string, it will be parsed as a Typst formula and converted to aTypstMathitemThe item will be placed in an appropriate location. By default, it’s next to the axis tip. Specifically controlled by
alpha,direction, andbuff:alphacontrols which point on the axis the item is placed next to. This value represents the percentage position on the axis. For example, the default1is the end of the axis, and0is the start of the axisdirectioncontrols which direction the item is placed relative to the aforementioned point. Default isUR, meaning upper rightbuffcontrols 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=Trueis 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 axisMultiple 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)