简体   繁体   中英

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

I'm using sns.factorplot to visualize the features importances ranking. Nine features was selected and they need to be ranked by how many iterations through before they were elimited by 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] .

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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