0

I wrote some code to interpret data attained from a dynamic ligth scattering experiment. The plot seems to work and show the linear trend from the plot. However, I need to get the equation of the magenta line in order to get the necessary variables for my project. Does anyone know how to do this? here is the section of code in question:

plt.figure()
plt.errorbar(q**2,1/tau1, 1/(tau1**2)*dtau1,marker='o',linestyle='none')

poptDp, pcovDp = curve_fit(lambda x, *p: x * p[0], q ** 2,1/tau1, p0=[1, 0], bounds=(0, 1000),
                           sigma=1/(tau1**2)*dtau1, ftol=1e-14, xtol=1e-14)  # old: 1e-15

plt.plot(q** 2 , q** 2  * poptDp[0] , color='magenta')
D=poptDp[0]
dD= np.sqrt(np.diag(pcovDp))[0]
plt.xlabel('q$^2$ ($\mathrm{\mu}$m$^{-2}$)')
plt.ylabel('$\Gamma_1$ (s$^{-1}$)')
plt.grid('on')
  • 5
    You know the equation as you're plotting it, it's `y = x * poptDp[0]`. If you want to put that on the legend you could add the `label` argument to your `plt.plot()` function then display the legend with `plt.legend()`? – Ari Cooper-Davis Jan 13 '22 at 16:09
  • 1
    Several ways are mentioned [here](https://stackoverflow.com/q/19125722/8881141). – Mr. T Jan 13 '22 at 18:15

0 Answers0