How to prevent overlapping x-axis labels in sns.countplot

后端 未结 5 814
天涯浪人
天涯浪人 2020-12-04 12:15

For the plot

sns.countplot(x=\"HostRamSize\",data=df)

I got the following graph with x-axis label mixing together, how do I avoid this? Sho

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-04 12:57

    plt.figure(figsize=(15,10)) #adjust the size of plot
    ax=sns.countplot(x=df['Location'],data=df,hue='label',palette='mako')
    
    ax.set_xticklabels(ax.get_xticklabels(), rotation=40, ha="right")  #it will rotate text on x axis
    
    plt.tight_layout()
    plt.show()
    

    you can try this code & change size & rotation according to your need.

提交回复
热议问题