如何使用matplotlib显示文本? [英] How to display a text with matplotlib?
本文介绍了如何使用matplotlib显示文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想这样做:
我有这个python代码:
I have this python code :
import numpy as np
import pylab as plt
a = np.array([1,2,3,4,5,6,7,8,9,10])
b = np.array([7,8,6,3,2,1,5,8,4,15])
c = plt.plot(a,b,'.')
d = 5
plt.text(2,3, "d = "+d) #This line is the problem because i have not the value of d !
plt.show()
所以实际上我只想显示d的值,但也想显示d的值,但是相对而言,例如在右下角,但不显示某些坐标.使用Python可以做到这一点吗?
So actually I just want to display the value of d and also I want to display the value of d but relatively for instance at the bottom right but not with some coordinates. Is it possible to do this with Python ?
非常感谢!
推荐答案
You can use the transform
argument to place in relative coordinates from 0.0
to 1.0
for example
plt.text(0.5,
0.67,
"d = {}".format(d),
transform=plt.gca().transAxes)
在此本地系统中,(0, 0)
是图的左下角,而(1, 1)
是图的右上角. 这是在绘图上的各个位置放置和旋转文本的很好的参考.
In this local system (0, 0)
is the lower-left and (1, 1)
is the upper-right of the plot. Here is a good reference for placing and rotating text at various locations on the plot.
这篇关于如何使用matplotlib显示文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文