Esempio n. 1
0
    def PlotLC(self,show=True,save=True,legend=True,residualscale=False,
        xlimits=None,ylimits=None,figsize=(13,8),incl_xrt=False):
        '''
        show: Plot to screen
        save: Save to disk
        legend: include a legend
        residualscale: BETA. CURRENTLY ONLY FOR USE WITH GRB120119A. HACK.
        xlimits: optional tuple of limits (observer frame)
        ylimits: optional tuple of limits (flux units)      
        figsize: figsize tuple in inches  
        '''
        # set font
        
        rc('font', family='Times New Roman')
        
        fig=plt.figure(figsize=figsize)
        ax=fig.add_axes([0.1,0.1,0.8,0.8])
        ax.loglog()
        
        # Plot the XRT data if desired
        if incl_xrt:
            obslist = ['BAT_unknown','XRT_unknown']
            for obstr in obslist:
                ob = self.obsdict[obstr]
                label= obstr.replace('_',' ')
                label= label.replace(' unknown','')
                detectinds = np.array([not a for a in ob.isupperlist])     
                ax.errorbar(np.array(ob.tmidlist)[detectinds],ob.fluxarr[detectinds],yerr=ob.fluxerrarr[detectinds], color=ob.color, fmt=ob.marker, label=label)
            
            leg=ax.legend(loc=3,borderaxespad=1.2,numpoints=1,frameon=False)
            from pylab import setp
            setp(leg.get_texts(),fontsize=20)
            setp(leg.get_title(),fontsize=20)
        
        ## HACK THiS IS AWFUL AND REMOVES DATA. for use ONLY for one time plots
        if residualscale:
            # first remove the xrt and bat data if it exists
            removelist = ['BAT_unknown','XRT_unknown']
            for key in removelist:
                if key in self.obsdict:
                    del(self.obsdict[key])
            
            
            from Modelling.ExtinctModel import CorrectFluxForGalExt
            
            filtlist=['K','H','J',"z'",'I',"i'",'R',"r'",'V','B'] # liverpool are just estimates!
            
            wave_Alist = []
            # loop through and grab the wavlengths for each filter
            for filttt in filtlist:
                for key, ob in self.obsdict.iteritems():
                    if ob.filtstr == filttt:
                        if ob.filt.wave_A not in wave_Alist:
                            wave_Alist.append(ob.filt.wave_A)
            
            wave_Alist = np.array(wave_Alist)
            removelist=[]
            fluxconv_uncorr = np.array([4312.1,2522.7,1358.6,654.0,456.1,340.6,193.6,160.6,109.9,45])
            fluxconv_uncorrerr=np.array([145.,80.,45.,26.,19,16.,8.2,6.7,5.1,2.5])
            fluxconv,fluxconverr = CorrectFluxForGalExt(self.galebv,wave_Alist,fluxconv_uncorr,fluxconv_uncorrerr)
            fluxconv = list(fluxconv)
            
            sed=zip(filtlist,fluxconv)
            for key, ob in self.obsdict.iteritems():
                if ob.filtstr not in filtlist:
                    removelist.append(key)
                else:
                    index = filtlist.index(ob.filtstr)
                    ob.gcfluxarr*=fluxconv[0]/fluxconv[index]
                    ob.gcfluxerrarr*=fluxconv[0]/fluxconv[index]
            for key in removelist:
                del(self.obsdict[key])
        ##HACK
        
        
        # get list of all sources of observations for use in legend-making
        sources = {}
        filters = []
        for key, ob in self.obsdict.iteritems():
            if ob.filt != None:
                if ob.filtstr not in filters:
                    filters.append(ob.filtstr)
                detectinds = np.array([not a for a in ob.isupperlist])
                if detectinds.any(): # only plot here if we have at least one detection
                    if ob.source not in sources: 
                        sources.update({ob.source:1}) #collecting number of detections for each filter for legend
                    else:
                        sources[ob.source]+=1
        print sources
        
        #HACK to get most number of sources to left. smarts has most. all alphabetical
        sourcenames = sources.keys()
        sourcenames.sort()
        sourcenames = sourcenames[::-1] #reverse; have smarts first
        # CAN HACK AS NECESSARY FOR NEW SOURCES - JUST PUT SOURCENAMES IN THE ORDER YOU WANT
        
        nsourcelist = [] # get the maximum number of instances for each source
        for nsource in sources.itervalues():
            nsourcelist.append(nsource)
        maxsource = max(nsourcelist)
        for key, nsource in sources.iteritems():
            sources[key] = abs(nsource-maxsource) #now the val is how many blank spaces to add for the legend
        print sources
            
        print filters
        
        for source in sourcenames: # loop through each source for ordering purposes
            i=0
            while i < sources[source]:
                ax.errorbar((100,100),(100,100),label=' ',color='white',marker=None)
                i+=1
            ax.errorbar((100,100),(100,100),label=source,color='white',marker=None)
            for key, ob in self.obsdict.iteritems():
                if ob.filt != None and ob.source == source:
                    upperinds = np.array(ob.isupperlist)
                    detectinds = np.array([not a for a in ob.isupperlist])
                    label = ob.filtstr
                    if detectinds.any(): # only plot here if we have at least one detection
                        ax.errorbar(np.array(ob.tmidlist)[detectinds],ob.gcfluxarr[detectinds],yerr=ob.gcfluxerrarr[detectinds], color=ob.color, fmt=ob.marker, label=label)
                    if upperinds.any(): # only plot here if we have at least one upper limit
                        ax.errorbar(np.array(ob.tmidlist)[upperinds],ob.gcfluxarr[upperinds],yerr=ob.gcfluxerrarr[upperinds], color=ob.color, fmt='v')
        # ax.set_ylim(1,1E5)
        
        if xlimits:
            ax.set_xlim(xlimits)
        if ylimits:
            ax.set_ylim(ylimits)        
        
        old_ylim=ax.get_ylim() # saving for later, as gets modified.. 
        
        ax2=ax.twinx()
        ax3=ax.twiny()
        ax3.loglog()
        
        xobstime=ax.get_xlim()
        xresttime0=xobstime[0]/(1+self.redshift)
        xresttime1=xobstime[1]/(1+self.redshift)
        xrest=(xresttime0,xresttime1)
        ax3.set_xlim(xrest)
        
        
        
        # duplicate axis for AB mag
        ax.set_ylim(old_ylim)
        ylimflux=ax.get_ylim()
        ylimmag0=flux2abmag(ylimflux[0])
        ylimmag1=flux2abmag(ylimflux[1])
        ylimmag=(ylimmag0,ylimmag1)
        ax2.set_ylim(ylimmag)
        
        # Label the axes
        ax.set_ylabel(r'$F_\nu$ (uJy)', size=20)
        zsubscript=str(self.redshift)
        topxlabel = r'$t_{z=%s}$ (s)'  % zsubscript
        ax.set_xlabel(r'$t$ (s)', size=20)
        ax2.set_ylabel('AB Mag',size=20)
        ax3.set_xlabel(topxlabel,size=20)
        
        
        for label in ax.xaxis.get_ticklabels():
            # label is a Text instance
            # label.set_color('red')
            # label.set_rotation(45)
            label.set_fontsize(20)
        for label in ax.yaxis.get_ticklabels():
            # label is a Text instance
            # label.set_color('red')
            # label.set_rotation(45)
            label.set_fontsize(20)
        for label in ax2.yaxis.get_ticklabels():
            # label is a Text instance
            # label.set_color('red')
            # label.set_rotation(45)
            label.set_fontsize(20)        
        for label in ax3.xaxis.get_ticklabels():
            # label is a Text instance
            # label.set_color('red')
            # label.set_rotation(45)
            label.set_fontsize(20)
        
        acceptlabels=['K','H','J',"z'","I","i'","R","r'","V","g'","B"]
        
        if legend:
            # hugely convoluted way to get the legend the way I want
            handles, labels = ax.get_legend_handles_labels()
            print handles
            print labels
            newhandles=[]
            newlabels=[]
            # sort the legend symbols
            i=0
            strt=0
            stop=maxsource+1  
            fullindices = np.arange(0,len(labels))   
            while i < len(sources):
                newsublabels=[]
                sorted_labels=[]
                new_lab_ind_tup=[]
                sublabels = labels[strt:stop]
                indices = np.arange(0,maxsource+1)   
                
                lab_ind_tup = zip(sublabels,indices)
                for labtup in lab_ind_tup:                    
                    if labtup[0] in sources or labtup[0] == ' ': #only deal with filters
                        new_lab_ind_tup.append(labtup)
                    else:
                        print acceptlabels.index(labtup[0])
                        sorted_labels.append((acceptlabels.index(labtup[0]),labtup))
                sorted_labels.sort()
                print sorted_labels
                for item in sorted_labels:
                    new_lab_ind_tup.append(item[1])
                print lab_ind_tup     
                print new_lab_ind_tup
                for indxx in np.arange(0,maxsource+1):
                    fullindices[lab_ind_tup[indxx][1]+strt]=new_lab_ind_tup[indxx][1]+strt
                print new_lab_ind_tup
                strt+=maxsource+1
                stop+=maxsource+1
                i+=1
            print fullindices
            for indd in fullindices:
                newlabels.append(labels[indd])
                newhandles.append(handles[indd])
            print newlabels
            leg = ax.legend()
            from pylab import setp
            setp(leg.get_texts(),fontsize=2)
            setp(leg.get_title(),fontsize=2)
            ax.legend(newhandles,newlabels,loc=3,numpoints=1,frameon=False,ncol=len(sources))

        if save:
            xrtstr=''
            if incl_xrt:
                xrtstr = '_xrt'
            filepath = storepath + 'LC_' + self.name.replace('\,','') + xrtstr + '.png' 
            fig.savefig(filepath)
            filepath = storepath + 'LC_' + self.name.replace('\,','') + xrtstr + '.pdf' 
            fig.savefig(filepath)
        if show:        
            fig.show()
Esempio n. 2
0
    def PlotLC(self,
               show=True,
               save=True,
               legend=True,
               residualscale=False,
               xlimits=None,
               ylimits=None,
               figsize=(13, 8),
               incl_xrt=False):
        '''
        show: Plot to screen
        save: Save to disk
        legend: include a legend
        residualscale: BETA. CURRENTLY ONLY FOR USE WITH GRB120119A. HACK.
        xlimits: optional tuple of limits (observer frame)
        ylimits: optional tuple of limits (flux units)      
        figsize: figsize tuple in inches  
        '''
        # set font

        rc('font', family='Times New Roman')

        fig = plt.figure(figsize=figsize)
        ax = fig.add_axes([0.1, 0.1, 0.8, 0.8])
        ax.loglog()

        # Plot the XRT data if desired
        if incl_xrt:
            obslist = ['BAT_unknown', 'XRT_unknown']
            for obstr in obslist:
                ob = self.obsdict[obstr]
                label = obstr.replace('_', ' ')
                label = label.replace(' unknown', '')
                detectinds = np.array([not a for a in ob.isupperlist])
                ax.errorbar(np.array(ob.tmidlist)[detectinds],
                            ob.fluxarr[detectinds],
                            yerr=ob.fluxerrarr[detectinds],
                            color=ob.color,
                            fmt=ob.marker,
                            label=label)

            leg = ax.legend(loc=3,
                            borderaxespad=1.2,
                            numpoints=1,
                            frameon=False)
            from pylab import setp
            setp(leg.get_texts(), fontsize=20)
            setp(leg.get_title(), fontsize=20)

        ## HACK THiS IS AWFUL AND REMOVES DATA. for use ONLY for one time plots
        if residualscale:
            # first remove the xrt and bat data if it exists
            removelist = ['BAT_unknown', 'XRT_unknown']
            for key in removelist:
                if key in self.obsdict:
                    del (self.obsdict[key])

            from Modelling.ExtinctModel import CorrectFluxForGalExt

            filtlist = ['K', 'H', 'J', "z'", 'I', "i'", 'R', "r'", 'V',
                        'B']  # liverpool are just estimates!

            wave_Alist = []
            # loop through and grab the wavlengths for each filter
            for filttt in filtlist:
                for key, ob in self.obsdict.iteritems():
                    if ob.filtstr == filttt:
                        if ob.filt.wave_A not in wave_Alist:
                            wave_Alist.append(ob.filt.wave_A)

            wave_Alist = np.array(wave_Alist)
            removelist = []
            fluxconv_uncorr = np.array([
                4312.1, 2522.7, 1358.6, 654.0, 456.1, 340.6, 193.6, 160.6,
                109.9, 45
            ])
            fluxconv_uncorrerr = np.array(
                [145., 80., 45., 26., 19, 16., 8.2, 6.7, 5.1, 2.5])
            fluxconv, fluxconverr = CorrectFluxForGalExt(
                self.galebv, wave_Alist, fluxconv_uncorr, fluxconv_uncorrerr)
            fluxconv = list(fluxconv)

            sed = zip(filtlist, fluxconv)
            for key, ob in self.obsdict.iteritems():
                if ob.filtstr not in filtlist:
                    removelist.append(key)
                else:
                    index = filtlist.index(ob.filtstr)
                    ob.gcfluxarr *= fluxconv[0] / fluxconv[index]
                    ob.gcfluxerrarr *= fluxconv[0] / fluxconv[index]
            for key in removelist:
                del (self.obsdict[key])
        ##HACK

        # get list of all sources of observations for use in legend-making
        sources = {}
        filters = []
        for key, ob in self.obsdict.iteritems():
            if ob.filt != None:
                if ob.filtstr not in filters:
                    filters.append(ob.filtstr)
                detectinds = np.array([not a for a in ob.isupperlist])
                if detectinds.any(
                ):  # only plot here if we have at least one detection
                    if ob.source not in sources:
                        sources.update(
                            {ob.source: 1}
                        )  #collecting number of detections for each filter for legend
                    else:
                        sources[ob.source] += 1
        print sources

        #HACK to get most number of sources to left. smarts has most. all alphabetical
        sourcenames = sources.keys()
        sourcenames.sort()
        sourcenames = sourcenames[::-1]  #reverse; have smarts first
        # CAN HACK AS NECESSARY FOR NEW SOURCES - JUST PUT SOURCENAMES IN THE ORDER YOU WANT

        nsourcelist = []  # get the maximum number of instances for each source
        for nsource in sources.itervalues():
            nsourcelist.append(nsource)
        maxsource = max(nsourcelist)
        for key, nsource in sources.iteritems():
            sources[key] = abs(
                nsource - maxsource
            )  #now the val is how many blank spaces to add for the legend
        print sources

        print filters

        for source in sourcenames:  # loop through each source for ordering purposes
            i = 0
            while i < sources[source]:
                ax.errorbar((100, 100), (100, 100),
                            label=' ',
                            color='white',
                            marker=None)
                i += 1
            ax.errorbar((100, 100), (100, 100),
                        label=source,
                        color='white',
                        marker=None)
            for key, ob in self.obsdict.iteritems():
                if ob.filt != None and ob.source == source:
                    upperinds = np.array(ob.isupperlist)
                    detectinds = np.array([not a for a in ob.isupperlist])
                    label = ob.filtstr
                    if detectinds.any(
                    ):  # only plot here if we have at least one detection
                        ax.errorbar(np.array(ob.tmidlist)[detectinds],
                                    ob.gcfluxarr[detectinds],
                                    yerr=ob.gcfluxerrarr[detectinds],
                                    color=ob.color,
                                    fmt=ob.marker,
                                    label=label)
                    if upperinds.any(
                    ):  # only plot here if we have at least one upper limit
                        ax.errorbar(np.array(ob.tmidlist)[upperinds],
                                    ob.gcfluxarr[upperinds],
                                    yerr=ob.gcfluxerrarr[upperinds],
                                    color=ob.color,
                                    fmt='v')
        # ax.set_ylim(1,1E5)

        if xlimits:
            ax.set_xlim(xlimits)
        if ylimits:
            ax.set_ylim(ylimits)

        old_ylim = ax.get_ylim()  # saving for later, as gets modified..

        ax2 = ax.twinx()
        ax3 = ax.twiny()
        ax3.loglog()

        xobstime = ax.get_xlim()
        xresttime0 = xobstime[0] / (1 + self.redshift)
        xresttime1 = xobstime[1] / (1 + self.redshift)
        xrest = (xresttime0, xresttime1)
        ax3.set_xlim(xrest)

        # duplicate axis for AB mag
        ax.set_ylim(old_ylim)
        ylimflux = ax.get_ylim()
        ylimmag0 = flux2abmag(ylimflux[0])
        ylimmag1 = flux2abmag(ylimflux[1])
        ylimmag = (ylimmag0, ylimmag1)
        ax2.set_ylim(ylimmag)

        # Label the axes
        ax.set_ylabel(r'$F_\nu$ (uJy)', size=20)
        zsubscript = str(self.redshift)
        topxlabel = r'$t_{z=%s}$ (s)' % zsubscript
        ax.set_xlabel(r'$t$ (s)', size=20)
        ax2.set_ylabel('AB Mag', size=20)
        ax3.set_xlabel(topxlabel, size=20)

        for label in ax.xaxis.get_ticklabels():
            # label is a Text instance
            # label.set_color('red')
            # label.set_rotation(45)
            label.set_fontsize(20)
        for label in ax.yaxis.get_ticklabels():
            # label is a Text instance
            # label.set_color('red')
            # label.set_rotation(45)
            label.set_fontsize(20)
        for label in ax2.yaxis.get_ticklabels():
            # label is a Text instance
            # label.set_color('red')
            # label.set_rotation(45)
            label.set_fontsize(20)
        for label in ax3.xaxis.get_ticklabels():
            # label is a Text instance
            # label.set_color('red')
            # label.set_rotation(45)
            label.set_fontsize(20)

        acceptlabels = [
            'K', 'H', 'J', "z'", "I", "i'", "R", "r'", "V", "g'", "B"
        ]

        if legend:
            # hugely convoluted way to get the legend the way I want
            handles, labels = ax.get_legend_handles_labels()
            print handles
            print labels
            newhandles = []
            newlabels = []
            # sort the legend symbols
            i = 0
            strt = 0
            stop = maxsource + 1
            fullindices = np.arange(0, len(labels))
            while i < len(sources):
                newsublabels = []
                sorted_labels = []
                new_lab_ind_tup = []
                sublabels = labels[strt:stop]
                indices = np.arange(0, maxsource + 1)

                lab_ind_tup = zip(sublabels, indices)
                for labtup in lab_ind_tup:
                    if labtup[0] in sources or labtup[
                            0] == ' ':  #only deal with filters
                        new_lab_ind_tup.append(labtup)
                    else:
                        print acceptlabels.index(labtup[0])
                        sorted_labels.append(
                            (acceptlabels.index(labtup[0]), labtup))
                sorted_labels.sort()
                print sorted_labels
                for item in sorted_labels:
                    new_lab_ind_tup.append(item[1])
                print lab_ind_tup
                print new_lab_ind_tup
                for indxx in np.arange(0, maxsource + 1):
                    fullindices[lab_ind_tup[indxx][1] +
                                strt] = new_lab_ind_tup[indxx][1] + strt
                print new_lab_ind_tup
                strt += maxsource + 1
                stop += maxsource + 1
                i += 1
            print fullindices
            for indd in fullindices:
                newlabels.append(labels[indd])
                newhandles.append(handles[indd])
            print newlabels
            leg = ax.legend()
            from pylab import setp
            setp(leg.get_texts(), fontsize=2)
            setp(leg.get_title(), fontsize=2)
            ax.legend(newhandles,
                      newlabels,
                      loc=3,
                      numpoints=1,
                      frameon=False,
                      ncol=len(sources))

        if save:
            xrtstr = ''
            if incl_xrt:
                xrtstr = '_xrt'
            filepath = storepath + 'LC_' + self.name.replace(
                '\,', '') + xrtstr + '.png'
            fig.savefig(filepath)
            filepath = storepath + 'LC_' + self.name.replace(
                '\,', '') + xrtstr + '.pdf'
            fig.savefig(filepath)
        if show:
            fig.show()
Esempio n. 3
0
    def PlotXRTlc(self,show=True,save=True,legend=True,
        obslist=['BAT_unknown','XRT_unknown','PAIRITEL_K'],
        xlimits=None,ylimits=None,figsize=None):
        '''
        show: Plot to screen
        save: Save to disk
        legend: include a legend
        obslist: parameters to plot
        xlimits: optional tuple of limits (observer frame)
        ylimits: optional tuple of limits (flux units)
        figsize: figsize tuple in inches
        '''
        # set font
        # EDIT TO SHOW MORE THAN JUST BAT/XRT/KBAND
        
        
        rc('font', family='Times New Roman')
        
        if not figsize:
            fig=plt.figure()
        else:
            fig=plt.figure(figsize=figsize)
        
        ax=fig.add_axes([0.1,0.1,0.8,0.8])
        ax.loglog()
        
        if not 'XRT_unknown' in self.obsdict:
            print 'Cannot find XRT data; skipping plot'
            return
        
        
        
        for obstr in obslist:
            ob = self.obsdict[obstr]
            label= obstr.replace('_',' ')
            label= label.replace(' unknown','')
            detectinds = np.array([not a for a in ob.isupperlist])     
            ax.errorbar(np.array(ob.tmidlist)[detectinds],ob.fluxarr[detectinds],yerr=ob.fluxerrarr[detectinds], color=ob.color, fmt=ob.marker, label=label)
        

        # COPY FROM PlotLC
        old_ylim=ax.get_ylim() # saving for later, as gets modified.. 
        
        ax2=ax.twinx()
        ax3=ax.twiny()
        ax3.loglog()
        
        if xlimits:
            ax.set_xlim(xlimits)
        if ylimits:
            ax.set_ylim(ylimits)
            
        xobstime=ax.get_xlim()
        xresttime0=xobstime[0]/(1+self.redshift)
        xresttime1=xobstime[1]/(1+self.redshift)
        xrest=(xresttime0,xresttime1)
        ax3.set_xlim(xrest)
        
        # duplicate axis for AB mag
        ax.set_ylim(old_ylim)
        ylimflux=ax.get_ylim()
        ylimmag0=flux2abmag(ylimflux[0])
        ylimmag1=flux2abmag(ylimflux[1])
        ylimmag=(ylimmag0,ylimmag1)
        ax2.set_ylim(ylimmag)
        
        # Label the axes
        ax.set_ylabel(r'$F_\nu$ (uJy)',size=16)
        zsubscript=str(self.redshift)
        topxlabel = r'$t_{z=%s}$ (s)'  % zsubscript
        ax.set_xlabel(r'$t$ (s)')
        ax2.set_ylabel('AB Mag',size=16)
        ax3.set_xlabel(topxlabel,size=16)
        
        ax.legend(loc=3,numpoints=1,frameon=False)
        if save:
            filepath = storepath + 'LCxrt_' + self.name.replace('\,','') + '.png' 
            fig.savefig(filepath)
            filepath = storepath + 'LCxrt_' + self.name.replace('\,','') + '.pdf' 
            fig.savefig(filepath)
        if show:        
            fig.show()
Esempio n. 4
0
    def PlotXRTlc(self,
                  show=True,
                  save=True,
                  legend=True,
                  obslist=['BAT_unknown', 'XRT_unknown', 'PAIRITEL_K'],
                  xlimits=None,
                  ylimits=None,
                  figsize=None):
        '''
        show: Plot to screen
        save: Save to disk
        legend: include a legend
        obslist: parameters to plot
        xlimits: optional tuple of limits (observer frame)
        ylimits: optional tuple of limits (flux units)
        figsize: figsize tuple in inches
        '''
        # set font
        # EDIT TO SHOW MORE THAN JUST BAT/XRT/KBAND

        rc('font', family='Times New Roman')

        if not figsize:
            fig = plt.figure()
        else:
            fig = plt.figure(figsize=figsize)

        ax = fig.add_axes([0.1, 0.1, 0.8, 0.8])
        ax.loglog()

        if not 'XRT_unknown' in self.obsdict:
            print 'Cannot find XRT data; skipping plot'
            return

        for obstr in obslist:
            ob = self.obsdict[obstr]
            label = obstr.replace('_', ' ')
            label = label.replace(' unknown', '')
            detectinds = np.array([not a for a in ob.isupperlist])
            ax.errorbar(np.array(ob.tmidlist)[detectinds],
                        ob.fluxarr[detectinds],
                        yerr=ob.fluxerrarr[detectinds],
                        color=ob.color,
                        fmt=ob.marker,
                        label=label)

        # COPY FROM PlotLC
        old_ylim = ax.get_ylim()  # saving for later, as gets modified..

        ax2 = ax.twinx()
        ax3 = ax.twiny()
        ax3.loglog()

        if xlimits:
            ax.set_xlim(xlimits)
        if ylimits:
            ax.set_ylim(ylimits)

        xobstime = ax.get_xlim()
        xresttime0 = xobstime[0] / (1 + self.redshift)
        xresttime1 = xobstime[1] / (1 + self.redshift)
        xrest = (xresttime0, xresttime1)
        ax3.set_xlim(xrest)

        # duplicate axis for AB mag
        ax.set_ylim(old_ylim)
        ylimflux = ax.get_ylim()
        ylimmag0 = flux2abmag(ylimflux[0])
        ylimmag1 = flux2abmag(ylimflux[1])
        ylimmag = (ylimmag0, ylimmag1)
        ax2.set_ylim(ylimmag)

        # Label the axes
        ax.set_ylabel(r'$F_\nu$ (uJy)', size=16)
        zsubscript = str(self.redshift)
        topxlabel = r'$t_{z=%s}$ (s)' % zsubscript
        ax.set_xlabel(r'$t$ (s)')
        ax2.set_ylabel('AB Mag', size=16)
        ax3.set_xlabel(topxlabel, size=16)

        ax.legend(loc=3, numpoints=1, frameon=False)
        if save:
            filepath = storepath + 'LCxrt_' + self.name.replace('\,',
                                                                '') + '.png'
            fig.savefig(filepath)
            filepath = storepath + 'LCxrt_' + self.name.replace('\,',
                                                                '') + '.pdf'
            fig.savefig(filepath)
        if show:
            fig.show()