Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash due to bad rounding in BarChart when no y_step was provided and the max y value was close to 0 #3935

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion manim/mobject/graphing/number_line.py
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# Handle cases where min and max are both positive or both negative
if x_min < x_max < 0 or x_max > x_min > 0:

to

# Handle cases where min and max are both positive or both negative
if x_min < x_max < 0 or x_max > x_min >= 0:

In the first commit (used for my renderings), I also added this change because a range from 0 to 0.000001 was not considered strictly positive or negative for some reason. I later reversed this change because it seemed to break a lot of tests. Maybe this is the cause of your troubles.

Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ def get_tick_range(self) -> np.ndarray:
x_max += 1e-6

# Handle cases where min and max are both positive or both negative
if x_min < x_max < 0 or x_max > x_min > 0:
if x_min < x_max < 0 or x_max > x_min >= 0:
tick_range = np.arange(x_min, x_max, x_step)
else:
start_point = 0
Expand Down
3 changes: 2 additions & 1 deletion manim/mobject/graphing/probability.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,8 @@ def __init__(
]

elif len(y_range) == 2:
y_range = [*y_range, round(max(self.values) / y_length, 2)]
y_step_target = max(self.values) / y_length
y_range = [*y_range, round(y_step_target, int(np.ceil(-np.log10(y_step_target))))]

if x_length is None:
x_length = min(len(self.values), config.frame_width - 2)
Expand Down
Loading