I have a set of data of 2 columns and with this data I made a scatterplot and a curve fit of the form a*X^b, where my data 'H' is on the x-axis and 'Q' on the y-axis, but I also want to display the equation in the plot and its correlation coeficient R (just what Excel does) but I can't get it. I appreciate all the suggestions and comments.
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()