I am trying to plot some data from a .fits file that contains count rate vs time. My goal is to over plot the count rates of different events in the same plot, with different times on three different x-axis. As the events I want to plot are periodic, I imposed a condition on the identification of the right times, so I can extract count rates only from the time ranges I need. This is my effort:
#!/usr/bin/env python
from scipy import *
from numpy import *
from pylab import *
from scipy import optimize
import pyfits, os, re, glob
import matplotlib.pyplot as plt
import matplotlib as mpl
from matplotlib.ticker import FuncFormatter
rc('font',**{'family':'serif','serif':['Helvetica']})
rc('ps',usedistiller='xpdf')
rc('text', usetex=True)
#------------------------------------------------------
tmin=56200
tmax=56249
data=pyfits.open('http://heasarc.gsfc.nasa.gov/docs/swift/results/transients/weak/GX304-1.orbit.lc.fits')
time = data[1].data.field(0)/86400. + data[1].header['MJDREFF'] + data[1].header['MJDREFI']
rate = data[1].data.field(1)
error = data[1].data.field(2)
data.close()
cond= ((time > tmin-5) & (time < tmax)) | ((time + 132.5 > tmin) & (time + 132.5 < tmax-10)) | ((time + 265 > tmin) & (time + 265 < tmax-12))
time=time[cond]
rate=rate[cond]
error=error[cond]
fig, ax1 = plt.subplots()
newax2 = ax1.twiny()
newax3 = ax1.twiny()
# Make some room at the bottom
fig.subplots_adjust(bottom=0.30)
newax2.set_frame_on(True)
newax2.patch.set_visible(False)
newax2.xaxis.set_ticks_position('bottom')
newax2.xaxis.set_label_position('bottom')
newax2.spines['bottom'].set_position(('outward', 20))
newax3.set_frame_on(True)
newax3.patch.set_visible(False)
newax3.xaxis.set_ticks_position('bottom')
newax3.xaxis.set_label_position('bottom')
newax3.spines['bottom'].set_position(('outward', 40))
#..plot the current light curve
errorbar(time, rate, error, fmt='r.', capsize=0)
gca().xaxis.set_major_formatter(FormatStrFormatter('%5.1f'))
#..overplot a previous outburst
errorbar(time + 122.5, rate, error, fmt='g.', capsize=0)
errorbar(time + 255, rate, error, fmt='k.', capsize=0)
axis([tmin-10,tmax,-0.00,0.45])
xlabel('Time, MJD')
ylabel("BAT cts/s/cm$^2$")
savefig("sync.eps",orientation='portrait',papertype='a4',format='eps')
os.system('gv sync.eps')
I am plotting three events, so I need three x-axis; however, I would like to write the correspective times on the x-axis with the correspective color too, if possible. The time reported on the bottom line is the correct one for the red curve, that is the most recent event. Any suggestions, please? Many thanks in advance.