setting spacing between grouped bar plots in matplotlib

前端 未结 3 1516
说谎
说谎 2020-12-08 05:53

I\'m trying to make a grouped bar plot in matplotlib, following the example in the gallery. I use the following:

import matplotlib.pyplot as plt
plt.figure(f         


        
3条回答
  •  南笙
    南笙 (楼主)
    2020-12-08 06:31

    Actually I think this problem is best solved by adjusting figsize and width; here is my output with figsize=(2,7) and width=0.3:

    enter image description here

    By the way, this type of thing becomes a lot simpler if you use pandas wrappers (i've also imported seaborn, not necessary for the solution, but makes the plot a lot prettier and more modern looking in my opinion):

    import pandas as pd        
    import seaborn 
    seaborn.set() 
    
    df = pd.DataFrame(groups, index=group_labels)
    df.plot(kind='bar', legend=False, width=0.8, figsize=(2,5))
    plt.show()
    

    enter image description here

提交回复
热议问题