Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get x axis labels in multiple line in matplotlib?

I'm trying to get the very long x axis label to multiple line as show in the encircled right image:

Example image

The code which I'm using currently:

ax = cluster3.plot(x='Neighborhood',y=['Population'],kind='bar',alpha=0.75,title='Population of Each Neighborhood',figsize=(15, 10))
ax.set_ylabel('Population')

cluster3 is the dataframe which has the Neighborhood column

like image 956
chronos203 Avatar asked Dec 24 '19 08:12

chronos203


Video Answer


1 Answers

Check this image: For wrapping

Or

df['cluster3'] = ['\n'.join(wrap(x, 12)) for x in  df['cluster3'])

apply this to your labels column to wrap the labels.

like image 181
Strange Avatar answered Oct 21 '22 14:10

Strange