manim.mobject.number_line.NumberLine

class NumberLine(x_range=None, length=None, unit_size=1, include_ticks=True, tick_size=0.1, numbers_with_elongated_ticks=None, longer_tick_multiple=2, color='#BBBBBB', rotation=0, stroke_width=2.0, include_tip=False, tip_width=0.25, tip_height=0.25, include_numbers=False, label_direction=array([0., - 1., 0.]), line_to_number_buff=0.25, decimal_number_config=None, numbers_to_exclude=None, numbers_to_include=None, number_scale_value=0.75, exclude_origin_tick=False, **kwargs)[source]

Bases: manim.mobject.geometry.Line

Creates a number line with tick marks. Number ranges that include both negative and positive values will be generated from the 0 point, and may not include a tick at the min / max values as the tick locations are dependent on the step size.

Parameters
  • x_range (Union[list, numpy.ndarray]) – The [x_min, x_max, x_step] values to create the line.

  • length (float) – The length of the number line.

  • unit_size (class:float) – The distance between each tick of the line.

  • include_ticks (bool) – Determines whether ticks are included.

  • tick_size (float) – The vertical length of each tick mark.

  • numbers_with_elongated_ticks (Union[list, numpy.ndarray]) – A list of specific values with elongated ticks.

  • longer_tick_multiple (float) – Influences how many times larger elongated ticks are than regular ticks (2 = 2x).

  • color (Colors) – The color of the line.

  • rotation (float) – The angle (in radians) at which the line is rotated.

  • stroke_width (float) – The thickness of the line.

  • include_tip (bool) – Determines whether a tip is added to the end of the line.

  • tip_width (float) – The width of the tip.

  • tip_height (float) – The height of the tip.

  • include_numbers (bool) – Determines whether numbers are added to tick marks. The number of decimal places is determined by the step size, this default can be overridden by decimal_number_config.

  • label_direction (Union[list, numpy.ndarray]) – The specific position to which number mobjects are added on the line.

  • line_to_number_buff (float) – The distance between the line and the number mobject.

  • decimal_number_config (dict) – Arguments that can be passed to DecimalNumber to influence number mobjects.

  • numbers_to_exclude (Union[list, numpy.ndarray]) – An explicit list of numbers to not be added to the line.

  • number_scale_value (float) – The size scaling factor for the number mobjects.

  • kwargs (Any) – Additional arguments to be passed to Line.

Examples

Example: NumberLineExample

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

class NumberLineExample(Scene):
    def construct(self):
        l0 = NumberLine(
            x_range=[-10, 10, 2],
            length=10,
            color=BLUE,
            include_numbers=True,
            label_direction=UP,
        )

        l1 = NumberLine(
            x_range=[-10, 10, 2],
            unit_size=0.5,
            numbers_with_elongated_ticks=[-2, 4],
            include_numbers=True,
            number_scale_value=0.5,
        )
        [num6] = [num for num in l1.numbers if num.number == 6]
        num6.set_color(RED)
        l1.add(num6)

        l2 = NumberLine(
            x_range=[-2.5, 2.5 + 0.5, 0.5],
            length=12,
            decimal_number_config={"num_decimal_places": 2},
            include_numbers=True,
        )

        l3 = NumberLine(
            x_range=[-5, 5 + 1, 1],
            length=6,
            include_tip=True,
            include_numbers=True,
            rotation=10 * DEGREES,
        )

        line_group = VGroup(l0, l1, l2, l3).arrange(DOWN, buff=1)
        self.add(line_group)
Returns

The constructed number line.

Return type

NumberLine

Methods

add_numbers

add_ticks

decimal_places_from_step

get_labels

get_number_mobject

get_number_mobjects

get_tick

get_tick_marks

get_tick_range

get_unit_size

get_unit_vector

n2p

Abbreviation for number_to_point

number_to_point

p2n

Abbreviation for point_to_number

point_to_number

rotate_about_number

rotate_about_zero

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.

n2p(number)[source]

Abbreviation for number_to_point

p2n(point)[source]

Abbreviation for point_to_number