跳至内容
Oxford PhysicsNotebook

GP49 / 大二

EL02 (copy)

静态 Notebook 阅读页:展示保存的代码和输出,未重新运行。

import numpy as np
import pandas as pd
df = pd.read_csv('3.csv')
lnA=df.LnA1.values
x =df.Distance.values
Aerror =df.Aerr.values
xerror =df.xerr.values
import matplotlib.pyplot as plt
#plt.scatter(t[843:875], T[843:875], label='v2', color='orange')


plt.title('Harmonic 4')
plt.xlabel('Distance x (mm)')
plt.ylabel('ln(Ax)')
plt.errorbar(x, lnA, yerr=Aerror, xerr=xerror,fmt='o', color='orange')
plt.legend()

plt.savefig('GP49_3.png')
<ipython-input-52-90b22f263e92>:9: UserWarning: No artists with labels found to put in legend.  Note that artists whose label start with an underscore are ignored when legend() is called with no argument.
  plt.legend()
<ipython-input-52-90b22f263e92>:11: MatplotlibDeprecationWarning: The x parameter as float was deprecated in Matplotlib 3.10 and will be removed in 3.12. Use int(x) instead.
  plt.savefig('GP49_3.png')
<ipython-input-52-90b22f263e92>:11: MatplotlibDeprecationWarning: The y parameter as float was deprecated in Matplotlib 3.10 and will be removed in 3.12. Use int(y) instead.
  plt.savefig('GP49_3.png')
Notebook 中保存的图表
<Figure size 640x480 with 1 Axes>
ds = 0.01
from scipy.optimize import curve_fit
def fit1(t, m, c):
    return m*t + c

popt,pcov=curve_fit(fit1, x, lnA, p0=None, sigma=ds)
print('a: ' +str(popt[0])+'    c:'+str(popt[1]))
print('Errors(a,c): '+ str(np.sqrt(np.diag(pcov))))
print(popt+1.959964*np.sqrt(pcov.diagonal()))
print(popt-1.959964*np.sqrt(pcov.diagonal()))
a: -0.01454069244275968    c:-2.208768920646853
Errors(a,c): [0.00313441 0.13594071]
[-0.00839737 -1.94233002]
[-0.02068401 -2.47520783]
import matplotlib.pyplot as plt
#plt.scatter(t[843:875], T[843:875], label='v2', color='orange')

plt.title('Harmonic 3')
plt.xlabel('Distance x (mm)')
plt.ylabel('ln(Ax)')
plt.errorbar(x, lnA, yerr=Aerror, xerr=xerror,fmt='o', color='orange')
plt.plot(x, fit1(x,popt[0],popt[1]))
plt.legend()

plt.savefig('GP49_fottedlinear.png')
<ipython-input-56-40d4a2a8d974>:9: UserWarning: No artists with labels found to put in legend.  Note that artists whose label start with an underscore are ignored when legend() is called with no argument.
  plt.legend()
<ipython-input-56-40d4a2a8d974>:11: MatplotlibDeprecationWarning: The x parameter as float was deprecated in Matplotlib 3.10 and will be removed in 3.12. Use int(x) instead.
  plt.savefig('GP49_fottedlinear.png')
<ipython-input-56-40d4a2a8d974>:11: MatplotlibDeprecationWarning: The y parameter as float was deprecated in Matplotlib 3.10 and will be removed in 3.12. Use int(y) instead.
  plt.savefig('GP49_fottedlinear.png')
Notebook 中保存的图表
<Figure size 640x480 with 1 Axes>