The columns in my dataframe has long names, so when I make a pairplot, the labels overlaps one another. I would like to rotate my labels 90 degrees, so they don’t collide. I tried looking up online and documentation, but could not find a solution. Here is something I wrote & the error message:
JavaScript
x
5
1
plt.figure(figsize=(10,10))
2
g = sn.pairplot(df, kind="scatter")
3
g.set_xticklabels(g.get_xticklabels(), rotation=90)
4
g.set_yticklabels(g.get_yticklabels(), rotation=90)
5
JavaScript
1
2
1
AttributeError: 'PairGrid' object has no attribute 'set_xticklabels'
2
How can I rotate labels (both x and y) in a Seaborn PairGrid?
Note: Sorry, my wifi can’t upload the image for reference.
Advertisement
Answer
Thanks to William’s answer, I now know what to look for to solve my problem!
Below is how I did it.
JavaScript
1
9
1
g = sn.pairplot(dfsub.sample(50), kind="scatter", hue=target)
2
for ax in g.axes.flatten():
3
# rotate x axis labels
4
ax.set_xlabel(ax.get_xlabel(), rotation = 90)
5
# rotate y axis labels
6
ax.set_ylabel(ax.get_ylabel(), rotation = 0)
7
# set y labels alignment
8
ax.yaxis.get_label().set_horizontalalignment('right')
9