标签: python pandas dataframe matplotlib
我有一个这样的数据框:
我想找到一种在matplotlib条形图中显示此内容的简单方法,其中各列分别是yaxis。如下图所示:
答案 0 :(得分:1)
使用seaborn并使用hue参数:
fig, ax = pyplot.subplots(figsize=(10, 10)) ax =seaborn.barplot( data= df.melt(id_vars='index').rename(columns=str.title), x= 'index', y= 'value', hue='varaible' )
答案 1 :(得分:0)
让我们尝试一下:
# sample data df = pd.DataFrame({'sum_prices':[100,200,300], 'properties':[10,5, 4]}, index=list('abc')) df.plot.bar(secondary_y=['properties'])
输出: