我想从以下数据中绘制一个小图:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
sales={'Apple':[50, 60, 40, 55],
'Orange': [40, 25, 35, 60],
'Cucumber': [10, 30, 40, 15],
'Banana': [70, 60, 40, 50],
'Peach':[10, 30, 40, 20],
'Melon': [5, 20, 70, 10],
'Berries': [30, 40, 50, 60]}
data=pd.DataFrame(sales, index=['Q1','Q2','Q3','Q4'])
我定义了一个函数,如下所示:
def bar_plots(df, bar_width, alpha=0.3, colors=None ):
indx=np.arange(df.shape[1])
for colm, idx, colr in zip(df.columns, indx, colors):
plt.bar([p+(bar_width*idx) for p in indx ], df[colm], alpha, colr, label=colm )
plt.xlabel('Quarters')
plt.ylabel('Sales')
plt.xticks(index + (bar_width*(len(indx))) / (len(indx)+1), ('Q1', 'Q2', 'Q3', 'Q4'))
调用该函数时出现以下错误:
bar_plots(data, 0.3, alpha=0.3, colors=['r','orange','g','y','coral','lime','b'] )
AttributeError: 'NoneType' object has no attribute 'update'
我不知道自己在哪里犯错,也感谢任何帮助。