Esempio n. 1
0
 def set_limits(self, axes=plt.gca(), nu_or_lambda='lambda'):
     # sets the limits of the plot Page
     plotSize = 0.9 # how much in percentace should the plotpage be larger
                    # than the plotted values?
     if nu_or_lambda=='nu':
         xLimNu = [min(self.flux_array[0]) -
                   min(self.flux_array[0]) * plotSize,
                   max(self.flux_array[0]) + max(self.flux_array[0])]
     if nu_or_lambda == 'lambda':
         newSelf_Flux_Array = []
         for i in self.flux_array[0]:
             newSelf_Flux_Array += [astro_functions.frequency_to_wavelength(i)]
         self.flux_array[0] = newSelf_Flux_Array
         xLimNu = [min(self.flux_array[0]) -
                   min(self.flux_array[0]) * 0.5 * plotSize,
                   max(self.flux_array[0]) +
                   max(self.flux_array[0]) * 2 *plotSize]
     ylim = [min(self.flux_array[1]) - min(self.flux_array[1]) * plotSize,
             max(self.flux_array[1]) +
             max(self.flux_array[1]) * plotSize / 2]
     # makes the plot page squared; TBD not really square yet
     axes.set_xlim(xLimNu[0],xLimNu[1])
     axes.set_ylim(ylim[0],ylim[1])
     return xLimNu,ylim
Esempio n. 2
0
    def create_figure(self, save=True, plotLegend=False,
                      color=['black'], marker=['x'], title=None, x_label=None,
                      y_label=None, nu_or_lambda='nu', fontdict=None,
                      textStringLoc=[1,1], lineWidth=0.5,
                      kappa='easy', x_range='normal', prefix="./", **kwargs):
        r""" Creates a quick preview of the loaded SED. TODO: extend
        documentation.
        """
        fig1 = plt.figure()
        fig1ax1 = fig1.add_subplot(111)
        textString = ''
        for i in range(len(self.p2[0])):
            textString += ('T=' + str('%1.1f' % self.p2[0][i]) +
                           ' K\nM=' + str("%1.2e" % self.p2[1][i]) + ' Msun\n')

        if len(self.p2[0])==2:
            textString+= 'N1/N2 = '+str('%i'%(self.p2[1][0]/self.p2[1][1]))+'\n'
        textString += ('beta = ' + str("%1.2f" % self.p2[2][0]) +
                       '\nchi$^2$ =' + str("%1.2f" % self.fit_chisq) + '\n')
        # sets the limits of the plot Page
        plotSize = 0.9 # how much in percentace should the plotpage be larger
                       # than the plotted values?
        if nu_or_lambda=='nu':
            xLimNu = [min(self.flux_array[0]) -
                      min(self.flux_array[0]) * plotSize,
                      max(self.flux_array[0]) + max(self.flux_array[0])]

        if nu_or_lambda == 'lambda':
            newSelf_Flux_Array = []
            for i in self.flux_array[0]:
                print i
                newSelf_Flux_Array += [astro_functions.frequency_to_wavelength(i)]

            self.flux_array[0] =newSelf_Flux_Array
            xLimNu = [min(self.flux_array[0]) -
                      min(self.flux_array[0]) * plotSize * 2,
                      max(self.flux_array[0]) +
                      max(self.flux_array[0]) * plotSize]
        ylim = [min(self.flux_array[1]) - min(self.flux_array[1]) * plotSize,
                max(self.flux_array[1]) +
                max(self.flux_array[1]) * plotSize / 2]
        # makes the plot page squared; TBD not really square yet
        fig1ax1.set_xlim(xLimNu[0],xLimNu[1])
        fig1ax1.set_ylim(ylim[0],ylim[1])

        # PLots the model given in self.p2
        self.plot_sed(axes=plt.gca(), nu_or_lambda=nu_or_lambda, color='black',
                      linewidth=0.5, x_range=x_range)

        markersize =7
        #Plotting the data points
        parted = [1]
        if len(parted)==1:
            fig1ax1.errorbar(self.flux_array[0], self.flux_array[1],
                         yerr=self.flux_array[2], fmt='o', marker='p',
                         mfc='None', mew=0.5, mec='#00ffff', ms=markersize,
                         color='black', lw=lineWidth)
        else:
            for i in range(len(parted)):
                if i == 0:
                    fig1ax1.errorbar(self.flux_array[0][0:parted[i]],
                                 self.flux_array[1][0:parted[i]],
                                 yerr=self.flux_array[2][0:parted[i]],
                                 fmt=marker[i],
                                 marker=marker[i], mfc='None', label=label[i],
                                 mew=0.5, mec=color[i], ms=markersize,
                                 color=color[i], lw=lineWidth)
                else:
                    fig1ax1.errorbar(self.flux_array[0][parted[i-1]:parted[i]],
                                self.flux_array[1][parted[i-1]:parted[i]],
                                yerr=self.flux_array[2][parted[i-1]:parted[i]],
                                fmt=marker[i], marker=marker[i],
                                mfc='None', label=label[i], mew=0.5,
                                mec=color[i], ms=markersize, color=color[i],
                                lw=lineWidth)

        # setting up legend,title, xlabel.
        if plotLegend == 'yes':
            fontdict={'size':'11'}
            plt.legend(loc='upper right', numpoints=1, fancybox=False,
                      prop=fontdict, markerscale=1)
        fontdict={'size':'17'}
        plt.text(90,0.2,s=textString, fontdict=fontdict, alpha=0.4)
        if title:
            fig1ax1.title(title)
        if x_label:
            fig1ax1.xlabel(x_label)
        if y_label:
            fig1ax1.ylabel(y_label)
        fig1ax1.axis([xLimNu[0],xLimNu[1],ylim[0],ylim[1]])
        if save:
            fig1.savefig(prefix + self.source_name + '_SED.eps', dpi=None,
                         facecolor='w', edgecolor='w',orientation='portrait',
                         papertype='a5', format='eps',bbox_inches='tight')