简体   繁体   English

如何在sns.factorplot中设置x轴的间隔?

[英]How to set the interval of the x-axis in sns.factorplot?

I'm using sns.factorplot to visualize the features importances ranking. 我正在使用sns.factorplot来可视化功能重要性排名。 Nine features was selected and they need to be ranked by how many iterations through before they were elimited by SVM-RFE . 选择了九个特征,它们需要按照SVM-RFE限制的迭代次数进行排序。

Figure like this 像这样

meanplot = pd.DataFrame(list(r.items()), columns=['Features','Ranking'])
meanplot = meanplot.sort_values('Ranking', ascending=False)
sns.factorplot(x="Ranking", y="Features", data = meanplot[:9], kind="bar", size=4, aspect=3.1, palette='coolwarm') 

The x-axis shows the iterations like [0,2,4,8] , but I want [0,1,2,3,4,5,6,7,8,9] . x轴显示迭代,如[0,2,4,8] ,但我想要[0,1,2,3,4,5,6,7,8,9]

You can refine the number of x-tick labels by first accessing the axis object returned by the factorplot and then providing a step size for the tick labels 您可以通过首先访问factorplot返回的轴对象,然后为tick标签提供step长来细化x-tick标签的数量

ax = sns.factorplot(x="Ranking", y="Features", data = meanplot[:9], kind="bar", size=4, aspect=3.1, palette='coolwarm') 
ax.set_xticklabels(step=1)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM