manim icon indicating copy to clipboard operation
manim copied to clipboard

NumberLine's default label precision rounds off-step ticks to duplicate integers

Open Don-Yin opened this issue 1 month ago • 3 comments

Description of bug / unexpected behavior

On Manim CE 0.22.0, NumberLine(x_range=[3.5, 7.5, 1], include_numbers=True) places ticks at 3.5, 4.5, 5.5, 6.5, 7.5, but labels them 4, 4, 6, 6, 8 by default. Thus distinct coordinates receive identical labels, and even the final displayed value lies outside the configured range.

I understand that the include_numbers documentation explicitly says that default decimal places are determined by the step size. This report concerns an edge case of that documented heuristic: a fractional tick origin can require greater precision than the step. It is not a claim that this is a new regression or that the existing precision rule is undocumented.

Expected behavior

When precision has not been explicitly set, labels should retain the precision needed for the actual tick values. In this example, the expected labels are 3.5, 4.5, 5.5, 6.5, 7.5.

Could the default precision account for the tick origin or the generated tick values, while preserving an explicit decimal_number_config override? If step-only precision is intentional, an explicit warning/example about off-step origins would help users avoid misleading labels.

How to reproduce the issue

Save as repro.py and run:

manim -ql -s repro.py OffStepLabels
from manim import NumberLine, Scene


class OffStepLabels(Scene):
    def construct(self):
        line = NumberLine(x_range=[3.5, 7.5, 1], include_numbers=True)
        self.add(line)
        print("tick values:", [float(n.get_value()) for n in line.numbers])
        print("decimal places:", [n.num_decimal_places for n in line.numbers])
        print(
            "label text:",
            ["".join(glyph.get_tex_string() for glyph in n) for n in line.numbers],
        )

The label text is read from the actual glyph mobjects, rather than inferred by rounding a separate list of numbers.

Actual output

Manim Community v0.22.0

tick values: [3.5, 4.5, 5.5, 6.5, 7.5]
decimal places: [0, 0, 0, 0, 0]
label text: ['4', '4', '6', '6', '8']

The rendered image also visibly contains 4 4 6 6 8.

rendered frame

Workaround and controls

An explicit precision works:

NumberLine(
    x_range=[3.5, 7.5, 1],
    include_numbers=True,
    decimal_number_config={"num_decimal_places": 1},
)

Additional checks on the same installation:

x_range Precision override Actual labels
[3.5, 7.5, 1] none 4, 4, 6, 6, 8
[3.5, 7.5, 1] 1 decimal place 3.5, 4.5, 5.5, 6.5, 7.5
[3, 7, 1] none 3, 4, 5, 6, 7
[3.5, 7.5, 1.0] none 3.5, 4.5, 5.5, 6.5, 7.5
[3.25, 5.25, 0.5] none 3.2, 3.8, 4.2, 4.8, 5.2

Changing 1 to 1.0 only happens to fix the first example; explicitly setting precision is the reliable workaround.

Related work and possible cause

  • #1653 reported decimal step sizes being ignored. #1667 fixed that by inferring precision from the step. The remaining case here uses an integer step and a fractional starting coordinate, so that earlier fix does not address it.
  • NumberLine.__init__ infers precision only from x_range[2], while get_tick_range uses x_min as the tick origin for entirely positive/negative ranges. The same relevant logic remains on current main at 3e19ee0; execution was tested on the released 0.22.0 package, not a source build of main.

System specifications

  • Manim Community: 0.22.0, Cairo renderer
  • Python: 3.14.8, conda-forge, Clang 20.1.8
  • OS: macOS 27.0 (26A5421a), arm64
  • RAM: 128 GiB
  • NumPy: 2.5.4
  • pycairo: 1.29.1; ManimPango: 0.7.0; Pillow: 13.0.0
  • TeX: TeX Live 2026, pdfTeX 1.40.29; dvisvgm 3.6
  • Rendering and TeX compilation complete successfully; this is a numeric-label issue, not a compilation failure.

AI-use disclosure

AI coding agents (Anthropic Claude and OpenAI GPT models) helped investigate, run the reproducer on Manim CE 0.22.0, and draft this report. I reviewed it before it was submitted from my account.

Don-Yin avatar Oct 23 '26 09:10 Don-Yin

Hey, I’d like to work on this issue.

ashlanserrao avatar Oct 23 '26 15:10 ashlanserrao

Hi, I’d like to work on this as part of my university coursework assignment. I’ll raise a PR soon.

Tarankalsi avatar Oct 25 '26 06:10 Tarankalsi

I've opened #5105 with a fix and tests for this.

Tarankalsi avatar Oct 27 '26 01:10 Tarankalsi