简体   繁体   English

如何在Seaborn中的因子图中调整标签之间的间距

[英]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. 对于数据分析和绘图需求,我一直非常喜欢Pandas和Seaborn的惊人组合。 It's been enough to prevent me from going down the path of learning R just for dataframes and ggplot ;P. 足以阻止我仅针对数据帧和ggplot; P学习R。 I'm having a small issue with the factorplot in seaborn and the way that it places labels on the x-axis. 我在seaborn中的factorplot及其将标签放置在x轴上的方式有一个小问题。 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). 基本上,我想“固定” x轴标签,以免最后一列“> = 35”被“挤压”(即与前面的标签重叠)。 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. 我想出了一种临时解决方案,将“> =”编码为unicode,并在标签前添加一个额外的空格,但是最好有一个通用的解决方案来强制标签之间的间距。

These are just matplotlib axis ticklabels at integral positions. 这些只是在积分位置处的matplotlib轴刻度标签。 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) (请注意,版本0.6+的单轴FacetGrid对象具有ax属性,这将使访问方法更加容易)

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

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