绘制条形图

时间:2019-11-17 10:40:56

标签: python pandas numpy matplotlib

see documentation

close()

错误:模块'pandas'没有属性'df1'

1 个答案:

答案 0 :(得分:2)

您的意思是pd.DataFrame

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

df2=pd.DataFrame({'Jan':np.random.randint(0,5,size=5),
            'Feb':np.random.randint(0,5,size=5),
            'Mar':np.random.randint(0,5,size=5),
})
df2.plot(kind='bar',stacked=True)
plt.legend(loc='upper left')
plt.show()

enter image description here

评论后编辑

data = {'Company Name':['GE', 'EON', 'NGP']
        , 'Sale1_percentage':[30, 23, 27]
           , 'Sale2_percentage':[28, 38, 29]
           , 'Sale3_percentage':[45, 44, 31]} 

df1 = pd.DataFrame(data) 

print(df1)

df1.plot(kind='bar',stacked=True)
plt.legend(loc='upper left')
plt.show()

enter image description here