Skip to content

plt.stackplot not working for integer input with non-default 'baseline' parameters #7802

Closed
@ulfaslak

Description

@ulfaslak

To help us understand and resolve your issue, please fill out the form to the best of your ability. You can feel free to delete the sections that do not apply.

Bug report

plt.stackplot with non-default 'baseline' keyword option not working for integer input.

I wanted to use plt.stackplot with the baseline='sym' option, and noticed that it a TypeError with my data. Turned out it was just a matter of changin the input valued to float types, but it should work for integer arrays too.

Code for reproduction

def fnx():
    return np.random.randint(5, 50, 10)

x = np.arange(10)
y1, y2, y3 = fnx(), fnx(), fnx()

fig, ax = plt.subplots()
ax.stackplot(x, y1, y2, y3, baseline="sym")
plt.show()

Actual outcome

TypeError: Cannot cast ufunc add output from dtype('float64') to dtype('int64') with casting rule 'same_kind'

Expected outcome

This nice figure:

screen shot 2017-01-11 at 18 35 19

Matplotlib version

  • Matplotlib version, Python version and Platform (Windows, OSX, Linux ...)
    version
>>> matplotlib.__version__
1.5.3
>>>matplotlib.pylab.__version__
1.11.3

Python version 2.7.12
Platform OSX Version 10.12

  • How did you install Matplotlib and Python (pip, anaconda, from source ...)
    pip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions