This commit is contained in:
zeFresk 2026-06-21 07:45:27 +00:00 committed by GitHub
commit 64a0183fdb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 22 additions and 1 deletions

View file

@ -310,7 +310,13 @@ class BarChart(Axes):
]
elif len(y_range) == 2:
y_range = [*y_range, round(max(self.values) / y_length, 2)]
y_step_target = max(self.values) / y_length
# Round the step size to a suitable (ceil) number of decimal places based on its magnitude (log10(x)). Avoids step size of 0.
# At least 2 decimals will be used in the case of large numbers.
y_range = [
*y_range,
round(y_step_target, max(2, int(np.ceil(-np.log10(y_step_target))))),
]
if x_length is None:
x_length = min(len(self.values), config.frame_width - 2)

View file

@ -0,0 +1,15 @@
from manim.mobject.graphing.probability import BarChart
def test_values_close_to_zero():
"""Checks that BarChart supports values/heights close to zero without crashing if ."""
values = [1 / 10000 for _ in range(8)]
names = list(range(len(values)))
chart = BarChart(
values=values,
bar_names=["one", "two", "three", "four", "five"],
y_range=[0, 2 / 10000],
y_length=6,
x_length=10,
x_axis_config={"font_size": 36},
)