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?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
Do you mean something like this:
?
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.
In Jupyter Notebook you might use something like this
or you can use:
I would suggest looking at the matplotlib gallery. At least two of the examples seem to be relevant:
Please check out this link: https://python-graph-gallery.com/7-custom-barplot-layout/
The result will be like this
Hopefully, it helps.