Skip to content

Commit 7cd3068

Browse files
tacaswellQuLogic
authored andcommitted
Merge pull request #7827 from anntzer/stackplot-integer-input
MNT: Cast stackplot input to float when required.
1 parent 2da8a98 commit 7cd3068

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

lib/matplotlib/stackplot.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ def stackplot(axes, x, *args, **kwargs):
6868

6969
baseline = kwargs.pop('baseline', 'zero')
7070
# Assume data passed has not been 'stacked', so stack it here.
71-
stack = np.cumsum(y, axis=0)
71+
# We'll need a float buffer for the upcoming calculations.
72+
stack = np.cumsum(y, axis=0, dtype=np.promote_types(y.dtype, np.float32))
7273

7374
if baseline == 'zero':
7475
first_line = 0.
@@ -79,7 +80,7 @@ def stackplot(axes, x, *args, **kwargs):
7980

8081
elif baseline == 'wiggle':
8182
m = y.shape[0]
82-
first_line = (y * (m - 0.5 - np.arange(0, m)[:, None])).sum(0)
83+
first_line = (y * (m - 0.5 - np.arange(m)[:, None])).sum(0)
8384
first_line /= -m
8485
stack += first_line
8586

0 commit comments

Comments
 (0)