# coding: utf-8 # SDSS Bootcamp # ============= # Python exercises # ---------------- # Download data 'a.fits' and 'a.csv' from http://astronomy.nmsu.edu/sdss_bootcamp/ # Note: Some of these commands are not necessary for python (instead of a notebook or ipython) # Import the packages we need to run this. You need astropy and matplotlib on your computer. These can be installed through Anaconda from astropy.io import ascii from astropy.io import fits import matplotlib.pyplot as plt get_ipython().magic(u'matplotlib inline') # Read in your data a=ascii.read('a.csv') f=fits.open('a.fits') data=f[1].data # Lets start plotting! plt.plot(a['snr']) plt.show() plt.plot(a['snr'],'ro') plt.show() plt.plot(a['snr'],'c+') plt.show() plt.plot(a['snr'],'m+') plt.show() plt.plot(a['snr'],'k^') plt.show() # Get some more information about our data. What is each column called? print data.columns # Now plot two quantities versus each other plt.plot(a['glon'],a['vhelio_avg']) plt.show() plt.plot(a['glon'],a['vhelio_avg'], 'go') plt.show() # You can add labels to your plot plt.plot(a['glon'],a['vhelio_avg'], 'go') plt.xlabel('Galactic longitude') plt.ylabel('Heliocentric radial velocity') plt.show() fig=plt.figure() ax1=fig.add_subplot(1,2,1) ax2=fig.add_subplot(1,2,2) ax1.plot(a['glon'],a['vhelio_avg'],'go') ax2.plot(a['glat'],a['vhelio_avg'],'go') ax1.set_xlabel('galactic longitude') ax2.set_xlabel('galactic latitude') ax1.set_ylabel('vhelio') ax2.set_ylabel('vhelio') plt.show() fig=plt.figure() ax=fig.add_subplot(1,1,1) ax.scatter(a['glon'],a['vhelio_avg']) # Make the same plot but use 'scatter' instead of 'plot'. It will do the same thing. fig=plt.figure() ax=plt.axes() ax.scatter(a['glon'],a['vhelio_avg'],c=a['snr'],vmin=80,vmax=200,s=200) # Make the same plot but with different plot sizes depending on galactic latitude fig=plt.figure() ax=plt.axes() ax.scatter(a['glon'],a['vhelio_avg'],c=a['snr'],vmin=80,vmax=200,s=(a['glat']-0.15)/0.15*100.+20)