Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Barchart with vertical labels in python/matplotlib

I'm using matplotlib to generate a (vertical) barchart. The problem is my labels are rather long. Is there any way to display them vertically, either in the bar or above it or below it?

like image 887
phihag Avatar asked Aug 03 '09 07:08

phihag


People also ask

How do I show vertical labels in Matplotlib?

In general, to show any text in matplotlib with a vertical orientation, you can add the keyword rotation='vertical' . Maybe you can also find useful the options 'verticalalignment' and 'horizontalalignment', which allows you to define how to align the text with respect to the ticks or the other elements.

How do you add labels to a bar plot in Python?

To add value labels on a Matplotlib bar chart, we can use the pyplot. text() function. The pyplot. text() function from the Matplotlib module is used to add text values to any location in the graph.


1 Answers

Do you mean something like this:

>>> from matplotlib import * >>> plot(xrange(10)) >>> yticks(xrange(10), rotation='vertical') 

?

In general, to show any text in matplotlib with a vertical orientation, you can add the keyword rotation='vertical'.

For further options, you can look at help(matplotlib.pyplot.text)

The yticks function plots the ticks on the y axis; I am not sure whether you originally meant this or the ylabel function, but the procedure is alwasy the same, you have to add rotation='vertical'

Maybe you can also find useful the options 'verticalalignment' and 'horizontalalignment', which allows you to define how to align the text with respect to the ticks or the other elements.

like image 96
dalloliogm Avatar answered Oct 21 '22 20:10

dalloliogm