在python图中添加其他信息?

use*_*180 5 python matplotlib

假设我们有一个图形,其中包含三个针对三个不同参数的图形。但是对于所有三个图,我们具有相同的温度T = 4K。然后如何在图中添加此信息?

我对在标题中写它不感兴趣。我想要它本身的形象。

tom*_*m10 8

figtext效果很好。

figtextover text和的优点annotate是,figtext默认使用图形坐标,而其他默认使用轴的坐标(因此,如果不同图形之间的轴不同,则“ T = 4K”将四处移动)。

import matplotlib.pyplot as plt

plt.figure()
plt.xlim(-10, 10)
plt.ylim(0, .01)
plt.figtext(.8, .8, "T = 4K")
plt.show()
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明


mta*_*add 6

这是使用的演示annotate。查看此示例以了解不同样式的注释。

import matplotlib.pyplot as plt
import numpy as np

plt.ion()
fig, ax = plt.subplots()

x = np.linspace(0,4,100)

plt.plot(x,2*x)
plt.plot(x,x**2)
plt.plot(x,np.sqrt(8*x))

ax.annotate('T = 4K', xy=(2,4), xycoords='data',
            xytext=(-100,60), textcoords='offset points',
            arrowprops=dict(arrowstyle='fancy',fc='0.6',
                            connectionstyle="angle3,angleA=0,angleB=-90"))

plt.show()
raw_input()
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述


rep*_*cus 2

好吧,我不确定你的意思,但你可以使用该text()方法将文本添加到图中。

在 matplotlib pyplot 中绘制文本