mirror of
https://github.com/ManimCommunity/manim.git
synced 2026-06-22 10:01:47 +00:00
Merge e1ae4428c3 into 0e83f4b09a
This commit is contained in:
commit
64a0183fdb
2 changed files with 22 additions and 1 deletions
|
|
@ -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)
|
||||
|
|
|
|||
15
tests/module/mobject/graphing/test_bar_chart.py
Normal file
15
tests/module/mobject/graphing/test_bar_chart.py
Normal 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},
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue