Python 如何在Matplotlib中制作groupby条形图

Python 如何在Matplotlib中制作groupby条形图,python,pandas,matplotlib,seaborn,Python,Pandas,Matplotlib,Seaborn,我想根据以下数据制作条形图: 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], 'M

我想根据以下数据制作条形图:

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'
我不知道我在哪里犯了错误,非常感谢你的帮助

您可以使用
plot(kind='bar')


@nimrodz谢谢你的回答。虽然熊猫和海伯恩可以做更简单的条形图,但我很有兴趣在matplotlib中进行教学
data.plot(kind='bar')