Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在pylab中的图形下添加图形描述_Python_Matplotlib - Fatal编程技术网

Python 在pylab中的图形下添加图形描述

Python 在pylab中的图形下添加图形描述,python,matplotlib,Python,Matplotlib,可能重复: 是否可以在pylab中的图形下添加图形描述 假设我绘制了以下图表: import pylab x = [1,2,3,2,4,5,6,4,7,8] pylab.plot(x) pylab.title('My Plot') pylab.xlabel('My x values') pylab.ylabel('My y values') pylab.show() 我还想插入几行描述图形的内容,可能是这样的(不是真正的代码): 可能吗 另外,我对pylab和matplotlib之间的

可能重复:

是否可以在pylab中的图形下添加图形描述

假设我绘制了以下图表:

import pylab

x = [1,2,3,2,4,5,6,4,7,8]

pylab.plot(x)
pylab.title('My Plot')
pylab.xlabel('My x values')
pylab.ylabel('My y values')

pylab.show()
我还想插入几行描述图形的内容,可能是这样的(不是真正的代码):

可能吗

另外,我对
pylab
matplotlib
之间的区别不太清楚,因此如果有一个解决方案在使用
matplotlib
时有效,它可能会起作用

提前感谢

非常有用,因为它会在地物坐标中添加文本,即x和y的0到1,而不考虑轴。下面是一个例子:

from pylab import *

figure()
gca().set_position((.1, .3, .8, .6)) # to make a bit of room for extra text
plot([1,2], [3,4])
figtext(.95, .9, "This is text on the side of the figure", rotation='vertical')
figtext(.02, .02, "This is text on the bottom of the figure.\nHere I've made extra room for adding more text.\n" + ("blah "*16+"\n")*3)
xlabel("an interesting axis label")    
show()

这里我使用了
轴。set_position()。在这里,我为大量文本添加了空间,这样文本就不会撞到轴标签上,尽管可能有点过多


虽然您要求在底部显示文本,但我通常会将此类标签放在侧面,这样它们更清楚地显示注释,而不是图形的一部分。(例如,我发现有一个小功能可以自动将生成每个图形的文件名放在图形上,这很有用。)
pylab
只是一个包装器,它从
numpy
scipy
matplotlib
导入必要的部分,以使打印变得简单。另见:@Wilduck,非常感谢!这就是我一直在寻找的。谢谢你的回答,但是当我尝试这样做时,图底部的文本与xlabel重叠。我试着玩
0.02
0.02
数字,但没用。你知道我是否能同时拥有底部的文本和xlabel?侧面的文本似乎非常方便。我已经更新了答案,以便在图的底部留出更多空间。在这里,我手动指定了额外的空间,虽然有几种方法可以手动缩小轴以增加文本空间,但我不知道有什么内置方法可以自动完成此操作。太完美了!非常感谢你!
from pylab import *

figure()
gca().set_position((.1, .3, .8, .6)) # to make a bit of room for extra text
plot([1,2], [3,4])
figtext(.95, .9, "This is text on the side of the figure", rotation='vertical')
figtext(.02, .02, "This is text on the bottom of the figure.\nHere I've made extra room for adding more text.\n" + ("blah "*16+"\n")*3)
xlabel("an interesting axis label")    
show()