8000 Fix some test warnings by QuLogic · Pull Request #7336 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Fix some test warnings #7336

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

Merged
merged 9 commits into from
Oct 27, 2016
Prev Previous commit
Next Next commit
Avoid divide-by-zero in stackplot.
The intention is there, but `np.where` does not really avoid the warning
since the division still occurs.
  • Loading branch information
QuLogic committed Oct 25, 2016
commit a1dbd55ace85a56d6b193da3889c271bc544a7dc
4 changes: 3 additions & 1 deletion lib/matplotlib/stackplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ def stackplot(axes, x, *args, **kwargs):
center = np.zeros(n)
total = np.sum(y, 0)
# multiply by 1/total (or zero) to avoid infinities in the division:
inv_total = np.where(total > 0, 1./total, 0)
inv_total = np.zeros_like(total)
mask = total > 0
inv_total[mask] = 1.0 / total[mask]
Copy link
Member

Choose a reason for hiding this comment

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

inv_total = np.reciprocal(total)
inv_total[total <= 0] = 0

Copy link
Member Author

Choose a reason for hiding this comment

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

np.reciprocal also warns about division by zero, which is the main reason for this change.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I have missed the warning message when tried np.reciprocal

increase = np.hstack((y[:, 0:1], np.diff(y)))
below_size = total - stack
below_size += 0.5 * y
Expand Down
0