0

I am not being able to generate a stacked graph with the error below:

TypeError: There is no Line2D property "stacked"

My csv has the format:

feb-17,1,2,3
apr-17,2,4,3
may-18,3,5,3
oct-20,4,1,1
dec-21,5,1,1

I would expect to see something like:

enter image description here

My code is:

import pandas
import matplotlib.pyplot as plt


df = pandas.read_csv(datacsv.csv, delimiter=',', 
                 index_col=0, 
                 parse_dates=[0], dayfirst=True, 
                 names=['Date','Black','Red', 'Yellow'])

df.plot(Stacked=True, marker='.',markersize=8, title ="My graph", fontsize = 10, color=['b','g','c'], figsize=(15, 15))

imagepathprotocol = "image.png"

plt.savefig(imagepathprotocol)

Any idea what can be done? Thanks a lot.

2 Answers 2

1

try the following code

df.plot(stacked=True,kind ='bar',title ="My graph",fontsize =10,color=['b','g','c'], figsize=(15, 15))

you need to point out the bar kind and delete the marker/markersize

Sign up to request clarification or add additional context in comments.

3 Comments

thanks for pointing me to the correct direction. Actually kind= bar didnt work but the following worked: df.plot.bar(stacked=True, title ="My graph", fontsize = 10, color=['b','g','c'], figsize=(15, 15))
“df.plot.bar()” should be equivalent to “df.plot(kind='bar')” it worked in my IDE
I know.. not sure why here I get an error. Thanks anyway!
0

Yes, change the type -

df.plot.bar(stacked=True, marker='.',markersize=8, title ="My graph", fontsize = 10, color=['b','g','c'], figsize=(15, 15))

By default it tries to plot a 2D line and this indeed does not have a stacked option.

See documentation here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.