Skip to content

Commit 506df7b

Browse files
committed
Fixed stackplot when all lines are zero at some index.
1 parent f859b74 commit 506df7b

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

lib/matplotlib/stackplot.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,12 @@ def stackplot(axes, x, *args, **kwargs):
9191
m, n = y.shape
9292
center = np.zeros(n)
9393
total = np.sum(y, 0)
94+
# multiply by 1/total (or zero) to avoid infinities in the division:
95+
inv_total = np.where(total > 0, 1./total, 0)
9496
increase = np.hstack((y[:, 0:1], np.diff(y)))
9597
below_size = total - stack
9698
below_size += 0.5 * y
97-
move_up = below_size / total
99+
move_up = below_size * inv_total
98100
move_up[:, 0] = 0.5
99101
center = (move_up - 0.5) * increase
100102
center = np.cumsum(center.sum(0))

0 commit comments

Comments
 (0)