简体   繁体   中英

How can I adjust the spacing between labels in a factorplot in Seaborn

I've been thoroughly enjoying the amazing combination of Pandas and Seaborn for my data analysis and plotting needs. It's been enough to prevent me from going down the path of learning R just for dataframes and ggplot ;P. I'm having a small issue with the factorplot in seaborn and the way that it places labels on the x-axis. Below is the example that's causing me trouble:

“压缩的” x轴标签

Basically, I want to "fix" the x-axis labels so that the final column ">=35" isn't so "squished" (ie overlapping the preceding label). Is there an easy way to do this? I came up with a temporary solution of encoding ">=" as unicode and adding an extra space before the label, but it would be nicer to have a general solution to enforce spacing between labels.

These are just matplotlib axis ticklabels at integral positions. So you could do

df = pd.DataFrame(dict(x=np.repeat(np.arange(21), 10), y=np.random.randn(210)))
df.loc[df.x == 20, "x"] = ">= 20"

g = sns.factorplot(x="x", y="y", data=df, kind="box")
g.axes[0, 0].set_xticks(range(20) + [20.5])

在此处输入图片说明

(Note that version version 0.6+ has an ax attribute on single-axes FacetGrid objects that will make accessing the methods a bit easier)

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