Skip to content

Fix BarChart ignoring include_numbers in y_axis_config - #5015

Open
RizgarOzan wants to merge 2 commits into
ManimCommunity:mainfrom
RizgarOzan:fix-barchart-y-axis-numbers
Open

RizgarOzan wants to merge 2 commits into
ManimCommunity:mainfrom
RizgarOzan:fix-barchart-y-axis-numbers

Conversation

@RizgarOzan

Copy link
Copy Markdown

Changelog

Fixed :class:.BarChart ignoring include_numbers in y_axis_config: y-axis numbers can now be suppressed, and are no longer added twice when include_numbers=True is passed.

Summary of Changes

Closes #3027 (the BarChart part; the NumberLine animation glitch mentioned later in the thread is separate and not touched here).

What / Why: BarChart.__init__ never merged y_axis_config defaults and always called self.y_axis.add_numbers() at the end. So y_axis_config={"include_numbers": False} had no effect, and y_axis_config={"include_numbers": True} created the number labels twice (NumberLine added them, then BarChart added them again).

How: instead of just deleting the add_numbers() call (the concern raised on the earlier attempt, #3057), BarChart now uses a default y_axis_config = {"include_numbers": True}, merged with the user-supplied config the same way x_axis_config already is, and passes it to Axes. The NumberLine then adds the numbers exactly once, or not at all. Default output is unchanged: NumberLine's include_numbers path calls add_numbers with the same tick range, exclusions and font size as the bare call did.

Also corrected the type hint of Axes._update_default_configs: it declared 1-tuples although Axes itself calls it with 3-tuples that may contain None; mypy flagged the new 2-tuple call.

How I tested:

  • Added tests/module/mobject/graphing/test_probability.py (uses label_constructor=Text, so it runs without LaTeX). Before the fix: pytest tests/module/mobject/graphing/test_probability.py -> 2 failed (assert [VGroup(...)] == [], assert 2 == 1). After: 2 passed.
  • pytest tests/module/mobject/graphing: 26 passed, 2 failed; the 2 failures (test_add_labels, test_NumberPlane) need LaTeX, which isn't installed on my machine, and fail the same way on main.
  • Compared default-chart y-axis numbers (values, positions, heights) with the previous behaviour for three configurations: identical.
  • pre-commit run --files <changed files>: ruff, ruff format, codespell, mypy pass.
  • I could not run the graphical tests in tests/test_graphical_units/test_probability.py locally (no LaTeX), so CI is the check there.

Checklist

  • I have read the Contributing Guidelines
  • I have written a descriptive PR title (see top of PR template for examples)
  • I have added a test case to prevent software regression

DecimalNumber caches digit mobjects in a module-level dict keyed only by
the digit string. Building the y-axis numbers with Text filled that cache
with Text glyphs, so later tests in the same pytest worker rendered their
numbers with Text instead of MathTex and failed frame comparison.
@RizgarOzan

Copy link
Copy Markdown
Author

The snapshot failures were caused by my new unit test, not the BarChart change. It built the y-axis numbers with Text, and DecimalNumber caches digit mobjects globally by string only (numbers.py), so later tests in the same worker rendered Text digits. Fixed in 5f57dd7 by using the default label constructor; running the unit test and both graphical files in one process now gives 33 passed, with no control data changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BarChart - y-axis labels/numbers cannot be suppressed

1 participant