How to plot a superimposed bar chart using matplotlib in python?

前端 未结 3 1943
春和景丽
春和景丽 2021-01-12 20:31

I want to plot a bar chart or a histogram using matplotlib. I don\'t want a stacked bar plot, but a superimposed barplot of two lists of data, for instance I have the follow

3条回答
  •  北海茫月
    2021-01-12 21:09

    It is actually simpler than the answers all over the internet make it appear.

    a = range(1,10)
    b = range(4,13)
    ind = np.arange(len(a))
    
    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.bar(x=ind, height=a, width=0.35,align='center')
    ax.bar(x=ind, height=b, width=0.35/3,  align='center')
    
    plt.xticks(ind, a)
    
    plt.tight_layout()
    plt.show()
    

提交回复
热议问题