How to print Y axis label horizontally in a matplotlib / pylab chart?(如何在 matplotlib/pylab 图表中水平打印 Y 轴标签?)
问题描述
我正在使用 matplotlib/pylab Python 模块创建非常简单的图表.标记 Y 轴的字母y"在其一侧.如果标签较长(例如单词),您会期望这样做,以免将图形的外部向左延伸太多.但是对于一个字母的标签,这是没有意义的,标签应该是直立的.我的搜索是空白的.如何水平打印y"?
I'm creating very simple charts with matplotlib / pylab Python module. The letter "y" that labels the Y axis is on its side. You would expect this if the label was longer, such as a word, so as not to extend the outside of the graph to the left too much. But for a one letter label, this doesn't make sense, the label should be upright. My searches have come up blank. How can I print the "y" horizontally?
推荐答案
很简单.绘制标签后,您可以简单地更改旋转:
It is very simple. After plotting the label, you can simply change the rotation:
from matplotlib import pyplot as plt
plt.ion()
plt.plot([1,2,3])
h = plt.ylabel('y')
h.set_rotation(0)
plt.draw()
或者,您可以将旋转作为参数传递,即
Alternatively, you can pass the rotation as an argument, i.e
plt.ylabel('y',rotation=0)
这篇关于如何在 matplotlib/pylab 图表中水平打印 Y 轴标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 matplotlib/pylab 图表中水平打印 Y 轴标签?


基础教程推荐
- 究竟什么是“容器"?在蟒蛇?(以及所有的 python 容器类型是什么?) 2022-01-01
- kivy 应用程序中的一个简单网页作为小部件 2022-01-01
- Python 中是否有任何支持将长字符串转储为块文字或折叠块的 yaml 库? 2022-01-01
- 比较两个文本文件以找出差异并将它们输出到新的文本文件 2022-01-01
- 在 Python 中将货币解析为数字 2022-01-01
- matplotlib 设置 yaxis 标签大小 2022-01-01
- Kivy 使用 opencv.调整图像大小 2022-01-01
- 在 Django Admin 中使用内联 OneToOneField 2022-01-01
- 对多索引数据帧的列进行排序 2022-01-01
- Python,确定字符串是否应转换为 Int 或 Float 2022-01-01