8000 Avoid divide-by-zero in stackplot. · matplotlib/matplotlib@a1dbd55 · GitHub
[go: up one dir, main page]

Skip to content

Commit a1dbd55

Browse files
committed
Avoid divide-by-zero in stackplot.
The intention is there, but `np.where` does not really avoid the warning since the division still occurs.
1 parent 580e1e3 commit a1dbd55

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

lib/matplotlib/stackplot.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ def stackplot(axes, x, *args, **kwargs):
9292
center = np.zeros(n)
9393
total = np.sum(y, 0)
9494
# multiply by 1/total (or zero) to avoid infinities in the division:
95-
inv_total = np.where(total > 0, 1./total, 0)
95+
inv_total = np.zeros_like(total)
96+
mask = total > 0
97+
inv_total[mask] = 1.0 / total[mask]
9698
increase = np.hstack((y[:, 0:1], np.diff(y)))
9799
below_size = total - stack
98100
below_size += 0.5 * y

0 commit comments

Comments
 (0)
0