Reputation: 1809
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:
Basically, I want to "fix" the x-axis labels so that the final column ">=35" isn't so "squished" (i.e. 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.
Upvotes: 1
Views: 2071
Reputation: 49022
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)
Upvotes: 2