[英]How to improve this seaborn countplot?
I used the following code to generate the countplot in python using seaborn: 我使用以下代码使用seaborn在python中生成了计数图:
sns.countplot( x='Genres', data=gn_s)
But I got the following output: 但是我得到以下输出:
I can't see the items on x-axis clearly as they are overlapping. 由于它们重叠,我无法在x轴上清楚看到它们。 How can I correct that?
我该如何纠正? Also I would like all the items to be arranged in a decreasing order of count.
另外,我希望所有项目以递减的顺序排列。 How can I achieve that?
我该如何实现?
You can use choose the x-axis
to be vertical, as an example: 您可以使用选择
x-axis
为垂直的示例,例如:
g = sns.countplot( x='Genres', data=gn_s)
g.set_xticklabels(g.get_xticklabels(),rotation=90)
Or, you can also do: 或者,您也可以执行以下操作:
plt.xticks(rotation=90)
Bring in matplotlib to set up an axis ahead of time, so that you can modify the axis tick labels by rotating them 90 degrees and/or changing font size. 提前引入matplotlib来设置轴,以便您可以通过将轴刻度标签旋转90度和/或更改字体大小来修改轴刻度标签。 To arrange your samples in order, you need to modify the source.
为了按顺序排列样本,您需要修改源。 I assume you're starting with a pandas dataframe, so something like:
我假设您从熊猫数据帧开始,所以类似:
data = data.sort_values(by='Genres', ascending=False) labels = # list of labels in the correct order, probably your data.index fig, ax1 = plt.subplots(1,1) sns.countplot( x='Genres', data=gn_s, ax=ax1) ax1.set_xticklabels(labels, rotation=90)
would probably help. 可能会有所帮助。
edit Taking andrewnagyeb 's suggestion from the comments to order the plot: 编辑从评论中采纳andrewnagyeb的建议以订购剧情:
sns.countplot( x='Genres', data=gn_s, order = gn_s['Genres'].value_counts().index)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.