我有这个密码
plt.figure()
plt.subplot(2,2,1)
x1 = delta_ST_all.iloc[0:47,15].values.reshape(-1, 1)
y1 = delta_ST_all.iloc[0:47,1].values.reshape(-1, 1)
linear_regressor = LinearRegression()
linear_regressor.fit(x1, y1)
y1_pred = linear_regressor.predict(x1)
plt.scatter(x1, y1, label='AE 220-225m', s=20, color='lightpink')
plt.plot(x1, y1_pred, color='lightpink')
但我想添加一个带有坡度和r^2的图例,有人能帮我吗? 我已经能够打印它并看到它,但我找不到代码将它放在图表上的图例中
通过
plt.text
:其中
slope
,r2
是您计算的值然后,文本将被放置在位置x=0.8,y=0.9,其中x和y是数据的值。 如果要将文字放置在相对于x、y轴(单位为正方形)的相对位置,则:
此处,文本将位于右上角,其中x=0.8,y=0.9,相对于轴
相关问题 更多 >
编程相关推荐