gpt4 book ai didi

python - 在 matplotlib 的绘图标签中显示数据

转载 作者:行者123 更新时间:2023-11-30 23:47:39 24 4
gpt4 key购买 nike

有没有办法在我绘制的图中显示变量(特别是线性拟合参数)?

还有,有没有办法控制显示的数字数量?

我使用 matplotlib 生成图形,并使用 optimize.curve_fit 进行曲线拟合。

最佳答案

当然,只需使用文本注释即可。

举个简单的例子:

import numpy as np
import matplotlib.pyplot as plt

# Generate data...
x = np.linspace(0, 30, 15)
y = 0.4 * x + 9 + np.random.random(x.size)

# Linear fit...
model = np.polyfit(x, y, deg=1)

plt.plot(x, y, 'bo', label='Observations')
plt.plot(x, model[0] * x + model[1], 'r-', label='Fitted Model')
plt.annotate(r'$y = {:.2f}x + {:.2f}$'.format(*model), xy=(0.1, 0.9),
xycoords='axes fraction', size=18)
plt.legend()

plt.show()

enter image description here

关于python - 在 matplotlib 的绘图标签中显示数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8281391/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com