你可以使用
text.
text(x, y, s, fontsize=12)
文本坐标可以相对于轴给出,因此文本的位置将独立于图的大小:
The default transform specifies that text is in data coords,
alternatively, you can specify text in axis coords (0,0 is lower-left
and 1,1 is upper-right). The example below places text in the center
of the axes::
text(0.5, 0.5,'matplotlib',
horizontalalignment='center',
verticalalignment='center',
transform = ax.transAxes)
防止文本干扰散射的任何一点是更加困难的事情.更简单的方法是将y_axis(ylim中的ymax((ymin,ymax)))设置为略高于点的最大y坐标的值.通过这种方式,您将始终拥有文本的可用空间.
编辑:这里有一个例子:
In [18]: f = figure()
In [19]: ax = f.add_subplot(111)
In [20]: scatter([3,5,2,6,8],[5,3,2,1,5])
Out[20]:
In [21]: text(0.1, 0.9,'matplotlib', ha='center', va='center', transform=ax.transAxes)
Out[21]:
In [22]:
ha和va参数设置文本相对于插入点的对齐方式.即. ha =’left’是一个很好的设置,用于在手动缩小(缩小)帧时防止长文本离开左轴.
如果觉得《python在左上角显示图片_python – 将文本放在matplotlib图的左上角》对你有帮助,请点赞、收藏,并留下你的观点哦!