# Python 5 plotting demo # Author: Babar Ali babar@ipac.caltech.edu # Date: 1-July-2014 # # use ipac-table-demo.py to read the data # in variable 'wdat' # # This script takes over from there. # # # Example 1: A simple plot # We use pylab # import pylab as PL PL.figure() # Start a new figure PL.plot(wdat['ra'], wdat['dec']) # plotting commands PL.show() # Lets see it. # plot() connects data points with a line. # Not so useful with (ra, dec) position plotting. # # # Example 2: Instead try scatter # PL.figure() PL.scatter(wdat['ra'], wdat['dec']) PL.show() # # Example 3: Lets add some details here # PL.figure() PL.scatter(wdat['ra'], wdat['dec'], color='red') PL.xlabel("RA (degrees)") #PL.xlabel("<$\\alpha$> (degrees)") # Can also use greek letters PL.ylabel("Declination (degrees)") PL.text(83.62, -5.22, "A text label") PL.savefig("example3.png") PL.close() # # Example 4: A histogram plot instead # PL.figure() bins = np.arange(min(wdat['ra']), max(wdat['ra']), 10./3600.) res = PL.bar(wdat['ra'], bins=bins) PL.show() # Can add labels, limits, texts, change colors with optional # keywords as above. # # Example 5: A color-magnitude plot # PL.figure() PL.scatter(wdat['w1mpro']-wdat['w2mpro'], wdat['w1mpro']) PL.show() # We don't like the lone points, so change the limits PL.figure() PL.scatter(wdat['w1mpro']-wdat['w2mpro'], wdat['w1mpro'], color='black', alpha=0.3) PL.xlim(-1.5, 3.0) PL.ylim(16.0, 3.0) PL.title("My First Color-Magnitude") PL.xlabel("W1-W2 (mag)") PL.ylabel("W1 (mag)") PL.show() # # Example 6: Subsets # # We will use two different colors to highlight two different # types of stars w1m2 = wdat['w1mpro']-wdat['w2mpro'] grp1 = np.where(w1m2<1.0) grp2 = np.where(w1m2>=1.0) PL.figure() PL.scatter(wdat['ra'][grp1], wdat['dec'][grp1], color='blue', label="W1-W2 < 1") PL.scatter(wdat['ra'][grp2], wdat['dec'][grp2], color='red', label="W1-W2 > 1") PL.xlabel("RA (degrees)") PL.ylabel("Dec (degrees)") PL.legend(loc="upper left", scatterpoints=1) PL.show() # # Where to find the API help # http://www.loria.fr/~rougier/teaching/matplotlib/ http://matplotlib.org/