In [1]:
from scipy.optimize import curve_fit
import astropy.io.ascii as ascii
import matplotlib.pyplot as plt
%matplotlib inline
import numpy as np
In [74]:
tab1=ascii.read("Table1.csv")
tab2=ascii.read("Table2.csv")
tab3=ascii.read("Table3.csv")
In [24]:
tab1
Out[24]:
In [56]:
plt.figure()
plt.errorbar(tab1['radius'],tab1['rvel'],yerr=tab1['rvelerr'],fmt='o',capsize=3)
plt.plot(tab1['radius'],tab1['Theoryval'],'-')
plt.plot(tab1['radius'],tab1['Ydiffval'],'--')
plt.title('Gas Dominated Dwarf (NGC 3741)')
plt.xlabel('Radius(in kpc)')
plt.ylabel('Rotational velocity (in km/s/Mpc)')
plt.savefig('gasdwarf.pdf')
plt.savefig('gasdwarf.jpeg')
In [79]:
def line(x, a, b):
return a * x + b
In [80]:
popt, pcov = curve_fit(line, tab1['radius'], tab1['Ydiffval'])
In [81]:
popt
Out[81]:
In [52]:
pcov
Out[52]:
In [82]:
plt.figure()
plt.errorbar(tab1['radius'],tab1['Ydiffval'],yerr=tab1['rvelerr'],fmt='o',capsize=3)
xfine = np.linspace(0., 7.5, 100) # define values to plot the function for
plt.plot(xfine, line(xfine, popt[0], popt[1]), 'r-')
plt.title('Gas Dominated Dwarf best fit')
plt.xlabel('Radius(in kpc)')
plt.ylabel('Rotational velocity (in km/s/Mpc)')
plt.savefig('gasdwarf_fit.pdf')
plt.savefig('gasdwarf_fit.jpeg')
In [75]:
tab2
Out[75]:
In [76]:
plt.figure()
plt.errorbar(tab2['Radius'],tab2['Rvelocity'],yerr=tab2['Velerr'],fmt='o',capsize=3)
plt.plot(tab2['Radius'],tab2['Theory'],'-')
plt.plot(tab2['Radius'],tab2['Veldiff'],'--')
plt.title('Disk-Dominated Spiral (NGC6503)')
plt.xlabel('Radius(in kpc)')
plt.ylabel('Rotational velocity (in km/s/Mpc)')
plt.savefig('diskspiral.pdf')
plt.savefig('diskspiral.jpeg')
In [84]:
popt2, pcov2 = curve_fit(line, tab2['Radius'], tab2['Veldiff'])
In [85]:
plt.figure()
plt.errorbar(tab2['Radius'],tab2['Veldiff'],yerr=tab2['Velerr'],fmt='o',capsize=3)
xfine = np.linspace(0., 25, 100) # define values to plot the function for
plt.plot(xfine, line(xfine, popt2[0], popt2[1]), 'r-')
plt.title('Disk-dominated Spiral best fit')
plt.xlabel('Radius(in kpc)')
plt.ylabel('Rotational velocity (in km/s/Mpc)')
plt.savefig('diskspiral_fit.pdf')
plt.savefig('diskspiral_fit.jpeg')
In [66]:
tab3
Out[66]:
In [69]:
plt.figure()
plt.errorbar(tab3['radius'],tab3['rvel'],yerr=tab3['velerr'],fmt='o',capsize=3)
plt.plot(tab3['radius'],tab3['Rtheory'],'-')
plt.plot(tab3['radius'],tab3['velerr'],'--')
plt.title('Bulge-Dominated Spiral (NGC7814)')
plt.xlabel('Radius(in kpc)')
plt.ylabel('Rotational velocity (in km/s/Mpc)')
plt.savefig('bulgespiral.pdf')
plt.savefig('bulgespiral.jpeg')
In [86]:
popt3, pcov3 = curve_fit(line, tab3['radius'], tab3['veldiff'])
In [88]:
plt.figure()
plt.errorbar(tab3['radius'],tab3['veldiff'],yerr=tab3['velerr'],fmt='o',capsize=3)
xfine = np.linspace(0., 20, 100) # define values to plot the function for
plt.plot(xfine, line(xfine, popt3[0], popt3[1]), 'r-')
plt.title('Bulge-dominated Spiral best fit')
plt.xlabel('Radius(in kpc)')
plt.ylabel('Rotational velocity (in km/s/Mpc)')
plt.savefig('bulgespiral_fit.pdf')
plt.savefig('bulgespiral_fit.jpeg')
In [91]:
popt, pcov = curve_fit(line, tab1['radius'][2:], tab1['Ydiffval'][2:])
In [90]:
tab1['radius'][2:]
Out[90]:
In [93]:
plt.figure()
plt.errorbar(tab1['radius'],tab1['Ydiffval'],yerr=tab1['rvelerr'],fmt='o',capsize=3)
xfine = np.linspace(0., 7.5, 100) # define values to plot the function for
plt.plot(xfine, line(xfine, popt[0], popt[1]), 'r-')
plt.title('Gas Dominated Dwarf best fit')
plt.xlabel('Radius(in kpc)')
plt.ylabel('Diff between theory & observed (in km/s/Mpc)')
plt.savefig('gasdwarf_diff_fit.pdf')
plt.savefig('gasdwarf_diff_fit.jpeg')
In [95]:
popt2, pcov2 = curve_fit(line, tab2['Radius'][4:], tab2['Veldiff'][4:])
plt.figure()
plt.errorbar(tab2['Radius'],tab2['Veldiff'],yerr=tab2['Velerr'],fmt='o',capsize=3)
xfine = np.linspace(0., 25, 100) # define values to plot the function for
plt.plot(xfine, line(xfine, popt2[0], popt2[1]), 'r-')
plt.title('Disk-dominated Spiral best fit')
plt.xlabel('Radius(in kpc)')
plt.ylabel('Diff between theory & observed (in km/s/Mpc)')
plt.savefig('diskspiral_diff_fit.pdf')
plt.savefig('diskspiral_diff_fit.jpeg')
In [96]:
popt3, pcov3 = curve_fit(line, tab3['radius'][2:], tab3['veldiff'][2:])
plt.figure()
plt.errorbar(tab3['radius'],tab3['veldiff'],yerr=tab3['velerr'],fmt='o',capsize=3)
xfine = np.linspace(0., 20, 100) # define values to plot the function for
plt.plot(xfine, line(xfine, popt3[0], popt3[1]), 'r-')
plt.title('Bulge-dominated Spiral best fit')
plt.xlabel('Radius(in kpc)')
plt.ylabel('Diff between theory & observed (in km/s/Mpc)')
plt.savefig('bulgespiral_diff_fit.pdf')
plt.savefig('bulgespiral_diff_fit.jpeg')
In [ ]: