import matplotlib.cm as cmap import matplotlib.pyplot as plt def plane(coord,a,b,c): """Function to define a plane""" return c-(coord[0]*a+coord[1]*b) coeefs=[1,-0.5,-1] col=linspace(-10,10,6) X,Y=meshgrid(col,col) Z=plane((X,Y),*coeefs)+normal(size=X.shape,scale=7.0) d=Data(column_stack((X.ravel(),Y.ravel(),Z.ravel())),filename="Fitting a Plane",setas="xyz") d.column_headers=["X","Y","Z"] d.figure(projection="3d") d.plot_xyz(plotter="scatter",c=cmap.jet(d.z)) d.curve_fit(plane,[0,1],2,result=True) d.setas="xy.z" d.plot_xyz(linewidth=0,cmap=cmap.jet) txt="$z=c-ax+by$\n" txt+="\n".join([d.format("plane:{}".format(k),latex=True) for k in ["a","b","c"]]) ax=plt.gca(projection="3d") ax.text(15,5,-50,txt) d.draw()
def plane(coord, a, b, c): """Function to define a plane""" return c - (coord[0] * a + coord[1] * b) coeefs = [1, -0.5, -1] col = linspace(-10, 10, 6) X, Y = meshgrid(col, col) Z = plane((X, Y), *coeefs) + normal(size=X.shape, scale=7.0) d = Data( column_stack((X.ravel(), Y.ravel(), Z.ravel())), filename="Fitting a Plane", setas="xyz", ) d.column_headers = ["X", "Y", "Z"] d.figure(projection="3d") d.plot_xyz(plotter="scatter") popt, pcov = d.curve_fit(plane, [0, 1], 2, result=True) d.setas = "xy.z" d.plot_xyz(linewidth=0, cmap=cmap.jet) txt = "$z=c-ax+by$\n" txt += "\n".join([d.format("plane:{}".format(k), latex=True) for k in ["a", "b", "c"]]) ax = plt.gca(projection="3d") ax.text(15, 5, -50, txt) d.draw()
d.show() #Now convert the angle to sin^2 t.apply(lambda x: np.sin(np.radians(x[0]/2.0))**2, 0,header=r"$sin^2\theta$") # Now create the m^2 order m=np.arange(len(t))+fringe_offset m=m**2 #And add it to t t.add_column(m, column_header='$m^2$') #Now we can it a straight line t.setas="x..y" fit=t.lmfit(Linear,result=True,replace=False,header="Fit") g=t["LinearModel:slope"] gerr=t["LinearModel:slope err"]/g g=np.sqrt(1.0/g) gerr/=2.0 l=float(d['Lambda']) th=l/(2*g) therr=th*(gerr) t.inset(loc="top right",width=0.5,height=0.4) t.plot_xy(r"Fit",r"$sin^2\theta$", 'b-',label="Fit") t.plot_xy(r"$m^2$",r"$sin^2\theta$", 'ro',label="Peak Position") t.xlabel="Fringe $m^2$" t.ylabel=r"$sin^2\theta$" t.title="" t.legend(loc="upper left") t.draw() pyplot.sca(t.axes[0]) # Get the wavelength from the metadata # Calculate thickness and report pyplot.text (0.05,0.05, "Thickness is: {} $\AA$".format(format_error(th,therr,latex=True)), transform=main_fig.axes[0].transAxes)
# And add it to t t.add_column(m, column_header="$m^2$") # Now we can it a straight line t.setas = "x..y" fit = t.lmfit(Linear, result=True, replace=False, header="Fit") g = t["LinearModel:slope"] gerr = t["LinearModel:slope err"] / g g = np.sqrt(1.0 / g) gerr /= 2.0 l = float(d["Lambda"]) th = l / (2 * g) therr = th * (gerr) t.inset(loc="top right", width=0.5, height=0.4) t.plot_xy(r"Fit", r"$sin^2\theta$", "b-", label="Fit") t.plot_xy(r"$m^2$", r"$sin^2\theta$", "ro", label="Peak Position") t.xlabel = "Fringe $m^2$" t.ylabel = r"$sin^2\theta$" t.title = "" t.legend(loc="upper left") t.draw() pyplot.sca(t.axes[0]) # Get the wavelength from the metadata # Calculate thickness and report pyplot.text( 0.05, 0.05, "Thickness is: {} $\AA$".format(format_error(th, therr, latex=True)), transform=main_fig.axes[0].transAxes, )