Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rotate tick labels for seaborn barplot

I am trying to display a chart with rotated x-axis labels, but the chart is not displaying.

import seaborn as sns %matplotlib inline  yellow='#FFB11E' by_school=sns.barplot(x ='Organization Name',y ='Score',data = combined.sort('Organization Name'),color=yellow,ci=None) 

At this point I can see the image, but after I set the xticklabel, I don't see the image anymore only an object reference. (I would post the image, but I don't enough reputation :()

by_school.set_xticklabels('Organization Name',rotation=45)  <matplotlib.axes._subplots.AxesSubplot at 0x3971a6a0> 

A similar question is posted here: Rotate label text in seaborn factorplot but the solution is not working.

like image 983
Laurennmc Avatar asked Aug 06 '15 15:08

Laurennmc


People also ask

How do I rotate a tick label?

Rotate X-Axis Tick Labels in Matplotlib There are two ways to go about it - change it on the Figure-level using plt. xticks() or change it on an Axes-level by using tick. set_rotation() individually, or even by using ax. set_xticklabels() and ax.


1 Answers

You need a different method call, namely .set_rotation for each ticklables. Since you already have the ticklabels, just change their rotations:

for item in by_school.get_xticklabels():     item.set_rotation(45) 

barplot returns a matplotlib.axes object (as of seaborn 0.6.0), therefore you have to rotate the labels this way. In other cases, when the method returns a FacetGrid object, refer to Rotate label text in seaborn factorplot

like image 128
CT Zhu Avatar answered Sep 16 '22 17:09

CT Zhu