Barchart与垂直标签在python / matplotlib [英] Barchart with vertical labels in python/matplotlib

查看:873
本文介绍了Barchart与垂直标签在python / matplotlib的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用matplotlib生成(垂直)barchart。问题是我的标签相当长。有任何方法可以在垂直方向显示它们,无论是在条形图中还是在其上方或下方?

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?

推荐答案

这:

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

一般来说,要以垂直方向显示matplotlib中的任何文本,您可以添加关键字 rotation ='vertical'

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

对于其他选项,您可以查看帮助(matplotlib.pyplot.text)

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

yticks函数绘制y轴;我不知道你最初是意味着这个还是ylabel函数,但程序是alwasy相同,你必须添加rotation ='垂直'

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'

也许你也可以找到有用的选项'verticalalignment'和'horizo​​ntalalignment',它允许您定义如何对齐文本相对于ticks或其他元素。

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.

这篇关于Barchart与垂直标签在python / matplotlib的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆