# Disclaimer: I'm sure there are many better ways to do the things listed # here - all I can say is these work! # # import some libraries we might need import numpy import math # matplotlib is documented at matplotlib.sourceforge.net # In particular, there are many helpful examples and a gallery which do # 90% of what you'd ever need. import matplotlib.pyplot as plt # Step 1: define the object fig fig = plt.figure(figsize=(7,7)) # Step 2: read in data data1 = numpy.loadtxt('uv_cii_highz.txt') data2 = numpy.loadtxt('uv_cii_lowz.csv',delimiter=',') data3 = numpy.loadtxt('uv_cii_agn.csv',delimiter=',') data4 = numpy.loadtxt('fir_fit.txt') uv_hiz = data1[:,0] cii_hiz= data1[:,1] uv_lowz= data2[:,0] cii_lowz= data2[:,2] uv_agn = data3[:,0] cii_agn= data3[:,2] uv_fir = data4[:,0] cii_fir= data4[:,1] # Step 3: define a subplot using the add_subplot method # (in this case the only one). An axis instance is returned, which # can be further operated on, as we'll see. # 111 is 1 row by 1 column, first position x11 = 19.0 x12 = 23.0 ax1 = fig.add_subplot(111,autoscale_on=False, xlim=(x11,x12),ylim = (32,38)) # Axis labeling is one weak point, I can't find much to do the fancy # font changes etc that you sometimes need, though limited subscripting # and superscripting does seem to be supported ax1.set_xlabel('Log$_{10}$(Ultraviolet luminosity (W/Hz))') ax1.set_ylabel('Log$_{10}$(L$_{[CII]}$ (W))') # to make two plots side-by side # ax1 = fig.add_subplot(121,autoscale_on=False, xlim=(0,1),ylim = (0,1)) # ax2 = fig.add_subplot(122,autoscale_on=False, xlim=(0,1),ylim = (0,1)) # It's also possible to have different axis scales on the top and bottom, # or left and right, axes by defining an ax2 object as the twin of ax1 x21 = 19.0-21.15 x22 = 22.0-21.15 ax2 = ax1.twiny() ax2.set_autoscale_on=False ax2.set_ylim(32,38) ax2.set_xlim(x21,x22) ax2.set_xlabel('Approximate star formation rate (solar masses/yr)') # plot # Note marker codes are typically two letters, the first is the color, # the second the symbol shape (e.g. bo = blue dot). See online help for # all the options. The edge color is determined by a separate keyword. ax1.plot(uv_hiz,cii_hiz,'bo',markersize=10.0,markeredgecolor='b', label='High redshift objects') ax1.plot(uv_lowz,cii_lowz,'r^',markersize=10.0,markeredgecolor='r', label='Low redshift galaxies') ax1.plot(uv_agn,cii_agn,'gx',markersize=10.0,markeredgecolor='r', label='Low redshift AGN') ax1.plot(uv_fir,cii_fir,'k--') # add a legend. The legend text is determined by the label arguments # to the "plot" method ax1.legend(loc=4,scatterpoints=1,numpoints=1) # save as postscript plt.savefig('test.eps',dpi=72,facecolor='w',edgecolor='w',orientation='portrait',transparent=False,format='eps') # to show the plot, type plt.show()