如何在Python中显示曲线拟合线的方程式?

问题描述

我有一组2列数据,并用此数据制作了散点图和曲线拟合形式a * X ^ b,其中我的数据“ H”在x轴上,而“ Q”在x轴上y轴,但我还想在图中显示方程式及其相关系数R(这正是Excel的功能),但我无法获得它。我感谢所有建议和评论。

import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
from scipy.optimize import curve_fit
datos=pd.read_excel('AforosLaBalsa.xlsx')
datos=datos[datos.Nivel !=0] #Elimina las filas donde la columna Nivel tenga 0
H = datos['Nivel']
Q = datos['Caudal']


#Se define la función para el ajuste
def regrpot(x,a,b):
    return a*x**b
Qn=Q+0.2*np.random.normal(size=len(H))
ajuste,cov= curve_fit(regrpot,H,Qn)
#Gráficos
fig=plt.figure(figsize=(5,5))
plt.plot(H,Q,'b^',label='Datos')
plt.xlabel('Nivel (m)')
plt.ylabel(r'$Q (m^{3}/s)$')


plt.plot(H,regrpot(H,*ajuste),'ro',label='Curva ajustada:') #Gráfico de la curva de ajuste
plt.legend()
plt.show()

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...