Ejemplo n.º 1
0
    def run(self):
        #Get the columns we need, in reduced form
        #since this is not MCMC
        weight = self.weight_col()
        weight = weight / weight.max()
        #Sort the final 500 samples, since they
        #are otherwise un-ordered
        weight[-500:] = np.sort(weight[-500:])

        #x-axis is just the iteration number
        x = np.arange(weight.size)

        #Choose a filename and make a figure for your plot.
        figure, filename = self.figure("nest_weight")

        #Do the plotting, and set the limits and labels
        pylab.plot(x, weight / weight.max())
        #pylab.xlim(-353, -341.5)
        pylab.xlim(0, 8000)
        pylab.xlabel("Iteration number $i$")
        pylab.ylabel(r"$p_i$")

        #Add some helpful text, on the title and the plot itself
        pylab.title("Normalised posterior weight $p_i$", size='medium')
        pylab.text(500,
                   0.4,
                   "Increasing likelihood,\n volume still large",
                   size="small")
        pylab.text(5500, 0.65, "Volume\ndecreasing", size='small')
        pylab.text(6500, 0.12, "Final $n_\mathrm{live}$\npoints", size='small')

        #Return the list of filenames we made
        return [filename]
 def plot(self):
     super(MatterPowerPlot, self).plot()
     done_any = False
     if self.power_files_exist("matter_power_lin"):
         self.plot_section("matter_power_lin", "Linear")
         done_any = True
     if self.power_files_exist("matter_power_nl"):
         self.plot_section("matter_power_nl", "Non-Linear")
         done_any = True
     if self.power_files_exist("matter_power_gal"):
         self.plot_section("matter_power_gal", "Galaxy")
         done_any = True
     if self.power_files_exist("matter_power_no_bao"):
         self.plot_section("matter_power_no_bao", "No BAO")
         done_any = True
     if self.power_files_exist("intrinsic_alignment_parameters"):
         self.plot_section("intrinsic_alignment_parameters",
                           "Intrinsic-intrinsic",
                           p_name='p_ii')
         done_any = True
     if self.power_files_exist("intrinsic_alignment_parameters"):
         self.plot_section("intrinsic_alignment_parameters",
                           "Shear-intrinsic",
                           p_name='p_gi')
         done_any = True
     if not done_any:
         raise IOError("Not making plot: %s (no data in this sample)" %
                       self.__class__.__name__[:-4])
     pylab.xlabel("$k / (Mpc/h)$")
     pylab.ylabel("$P(k) / (h^1 Mpc)^3$")
     pylab.grid()
     pylab.legend()
 def plot(self):
     super(DistancePlot, self).plot()
     z = self.load_file("distances", "z")
     d = self.load_file("distances", self.distance)
     pylab.plot(z, d * self.scaling)
     pylab.grid()
     pylab.xlabel("Redshift z")
     pylab.ylabel(self.name)
 def plot(self):
     super(LuminositySlopePlot, self).plot()
     section = "galaxy_luminosity_function"
     z = self.load_file(section, "z")
     alpha = self.load_file(section, "alpha")
     pylab.plot(z, alpha)
     pylab.grid()
     pylab.xlabel("Redshift z")
     pylab.ylabel("Luminosity Function Slope $\\alpha$")
 def plot(self):
     super(CMBSpectrumPlot, self).plot()
     ell = self.load_file("cmb_cl", "ell")
     c_ell = self.load_file("cmb_cl", self.name)
     pylab.plot(ell, c_ell)
     pylab.grid()
     pylab.xlabel("$\\ell$")
     pylab.ylabel("$\\ell(\\ell+1) C_\\ell/2\\pi \\mathrm{" +
                  self.name.upper() + "} / uK^2$")
 def plot(self):
     super(GrandPlot, self).plot()
     ell = self.load_file("cmb_cl", "ell")
     for name in ['tt', 'ee', 'te', 'bb']:
         c_ell = self.load_file("cmb_cl", name)
         pylab.loglog(ell, abs(c_ell), label=name.upper())
     pylab.legend()
     pylab.grid()
     pylab.xlabel("$\\ell$")
     pylab.ylabel("$\\ell(\\ell+1) C_\\ell/2\\pi / uK^2$")
 def plot(self):
     super(GrowthPlot, self).plot()
     section = "growth_parameters"
     z = self.load_file(section, "z")
     d_z = self.load_file(section, "d_z")
     f_z = self.load_file(section, "f_z")
     pylab.plot(z, d_z, label='$d(z)$')
     pylab.plot(z, f_z, label='$f(z)$')
     pylab.grid()
     pylab.xlabel("Redshift z")
     pylab.ylabel("Growth Functions")
     pylab.legend(loc='center right')
    def plot(self):
        super(ShearCorrelationMinusPlot, self).plot()
        nbin = 0
        for i in range(1, 100):
            filename = self.file_path("shear_xi_minus",
                                      "bin_{0}_{0}".format(i))
            if os.path.exists(filename):
                nbin += 1
            else:
                break
        if nbin == 0:
            IOError("No data for plot: %s" % self.__class__.__name__[:-4])

        theta = self.load_file("shear_xi_minus", "theta")
        sz = 1.0 / (nbin + 2)
        for i in range(1, nbin + 1):
            for j in range(1, i + 1):
                rect = (i * sz, j * sz, sz, sz)
                self.figure.add_axes(rect)
                #pylab.ploy()
                #pylab.subplot(nbin, nbin, (nbin*nbin)-nbin*(j-1)+i)
                xi = self.load_file("shear_xi_minus",
                                    "bin_{0}_{1}".format(i, j))
                pylab.loglog(theta, xi)
                pylab.xlim(1e-4, 1e-1)
                pylab.ylim(2e-7, 1e-3)
                if i == 1 and j == 1:
                    pylab.xlabel("$\\theta$")
                    pylab.ylabel("$\\xi_+(\\theta)$")
                else:
                    pylab.gca().xaxis.set_ticklabels([])
                    pylab.gca().yaxis.set_ticklabels([])

                pylab.gca().tick_params(length=0.0, which='minor')
                pylab.gca().tick_params(length=3.0, which='major')
                pylab.gca().tick_params(labelsize=10)

                pylab.text(1.5e-3,
                           1.8e-4,
                           "(%d,%d)" % (i, j),
                           fontsize=8,
                           color='red')

                pylab.grid()
    def plot_section(self, section):
        nbin = 0
        for i in range(1, 100):
            filename = self.file_path(section, "bin_{0}_{0}".format(i))
            if os.path.exists(filename):
                nbin += 1
            else:
                break
        if nbin == 0:
            IOError("No data for plot: %s" % self.__class__.__name__[:-4])

        ell = self.load_file(section, "ell")
        sz = 1.0 / (nbin + 2)
        for i in range(1, nbin + 1):
            for j in range(1, i + 1):
                rect = (i * sz, j * sz, sz, sz)
                self.figure.add_axes(rect)
                #pylab.ploy()
                #pylab.subplot(nbin, nbin, (nbin*nbin)-nbin*(j-1)+i)
                cl = self.load_file(section, "bin_{0}_{1}".format(i, j))

                if all(cl <= 0):
                    cl *= -1
                pylab.loglog(ell, ell * (ell + 1.) * cl / 2 / np.pi)
                pylab.ylim(*self.ylim)
                if i == 1 and j == 1:
                    pylab.xlabel("$\\ell$")
                    pylab.ylabel("$\\ell (\\ell+1) C_\\ell / 2 \\pi$")
                else:
                    pylab.gca().xaxis.set_ticklabels([])
                    pylab.gca().yaxis.set_ticklabels([])
                pylab.gca().tick_params(length=0.0, which='minor')
                pylab.gca().tick_params(length=3.0, which='major')
                pylab.gca().tick_params(labelsize=10)

                if section == "shear_cl":
                    pylab.text(1.5 * ell.min(),
                               1.8e-4,
                               "(%d,%d)" % (i, j),
                               fontsize=8,
                               color='red')
                    pylab.grid()
Ejemplo n.º 10
0
    def make_2d_plot(self, name1, name2):
        #Get the data
        if 'planck' in self.source.name.lower():

            def smooth_likelihood(obj, x, y):
                n = obj.options.get("n_kde", 100)
                factor = obj.options.get("factor_kde", 2.0)
                kde = KDE([x, y], factor=factor)
                x_range = (x.min(), x.max())
                y_range = (y.min(), y.max())
                (x_axis,
                 y_axis), like = kde.grid_evaluate(n, [x_range, y_range])
                return n, x_axis, y_axis, like

            x = self.reduced_col(name1)
            y = self.reduced_col(name2)

        else:
            if name1[-2:] == 's8':
                omm = self.reduced_col('cosmological_parameters--omega_m')
                sigma_8 = self.reduced_col('cosmological_parameters--sigma_8')
                x = sigma_8 * (omm / 0.3)**0.5
            else:
                x = self.find_or_pad(name1)
            if name2[-2:] == 's8':
                omm = self.reduced_col('cosmological_parameters--omega_m')
                sigma_8 = self.reduced_col('cosmological_parameters--sigma_8')
                y = sigma_8 * (omm / 0.3)**0.5
            else:
                y = self.find_or_pad(name2)

        if x.max() - x.min() == 0 or y.max() - y.min() == 0:
            return
        print "  (making %s vs %s)" % (name1, name2)

        #import pdb ; pdb.set_trace()

        #Interpolate using KDE
        try:
            n, x_axis, y_axis, like = self.smooth_likelihood(x, y)
        except:
            try:
                n, x_axis, y_axis, like = self.smooth_likelihood_noweight(x, y)
            except:

                def smooth_likelihood(obj, x, y):
                    n = 100
                    factor = 2.0
                    kde = KDE([x, y], factor=factor)
                    x_range = (x.min(), x.max())
                    y_range = (y.min(), y.max())
                    (x_axis,
                     y_axis), like = kde.grid_evaluate(n, [x_range, y_range])
                    return n, x_axis, y_axis, like

                n, x_axis, y_axis, like = smooth_likelihood(self, x, y)

        figure, filename = self.figure("2D", name1, name2)

        #Choose levels at which to plot contours

        contour1 = 1 - 0.68
        contour2 = 1 - 0.95
        try:
            level1, level2, total_mass = self._find_contours(
                like, x, y, n, x_axis[0], x_axis[-1], y_axis[0], y_axis[-1],
                contour1, contour2)
        except:

            def find_contours(like, x, y, n, xmin, xmax, ymin, ymax, contour1,
                              contour2):
                N = len(x)
                x_axis = np.linspace(xmin, xmax, n + 1)
                y_axis = np.linspace(ymin, ymax, n + 1)
                histogram, _, _ = np.histogram2d(x, y, bins=[x_axis, y_axis])

                def objective(limit, target):
                    w = np.where(like >= limit)
                    count = histogram[w]
                    return count.sum() - target

                target1 = histogram.sum() * (1 - contour1)
                target2 = histogram.sum() * (1 - contour2)

                level1 = scipy.optimize.bisect(objective,
                                               like.min(),
                                               like.max(),
                                               args=(target1, ))
                level2 = scipy.optimize.bisect(objective,
                                               like.min(),
                                               like.max(),
                                               args=(target2, ))
                return level1, level2, like.sum()

            level1, level2, total_mass = find_contours(like, x, y, n,
                                                       x_axis[0], x_axis[-1],
                                                       y_axis[0], y_axis[-1],
                                                       contour1, contour2)
            #import pdb ; pdb.set_trace()
        level0 = 1.1
        levels = [level2, level1, level0]
        #Create the figure
        fig, filename = self.figure("2D", name1, name2)
        pylab.figure(fig.number)

        #Make the plot
        #pylab.figure(figure.number, figsize=(8,7))
        keywords = self.keywords_2d()
        fill = self.options.get("fill", True)
        if self.fill_list != None:
            fill = self.fill_list[self.source.index]
        imshow = self.imshow[self.source.index]
        #plot_points = self.options.get("plot_points", False)
        color = self.colors[self.source.index]
        linestyle = self.linestyles[self.source.index]
        if self.linecolors[self.source.index] is not None:
            linecolor = self.linecolors[self.source.index]
        else:
            linecolor = color
        print self.source.index, linecolor

        if self.opaque_list[self.source.index]:
            pylab.contourf(x_axis,
                           y_axis,
                           like.T, [level2, level0],
                           colors=['white'])
        print "fill", self.source.index, fill

        if imshow:
            pylab.imshow(like.T,
                         extent=(x_axis[0], x_axis[-1], y_axis[0], y_axis[-1]),
                         aspect='auto',
                         origin='lower',
                         cmap=cmap_white_to_color(color))
        elif fill:
            if self.fill_colors[self.source.index] is not None:
                c = self.fill_colors[self.source.index]
                pylab.contourf(x_axis,
                               y_axis,
                               like.T, [level2, level0],
                               colors=[c[0]])
                pylab.contourf(x_axis,
                               y_axis,
                               like.T, [level1, level0],
                               colors=[c[1]])
            else:
                pylab.contourf(x_axis,
                               y_axis,
                               like.T, [level2, level0],
                               colors=[color],
                               alpha=self.alphas[self.source.index])
                if self.opaque_centre[self.source.index]:
                    pylab.contourf(x_axis,
                                   y_axis,
                                   like.T, [level1, level0],
                                   colors=[color])
                else:
                    pylab.contourf(x_axis,
                                   y_axis,
                                   like.T, [level1, level0],
                                   colors=[color],
                                   alpha=self.alphas[self.source.index])
        if (not fill) or self.line_list[self.source.index]:
            print self.source.index, linecolor
            pylab.contour(x_axis,
                          y_axis,
                          like.T, [level2, level1],
                          colors=[linecolor],
                          linestyles=linestyle,
                          linewidths=self.linewidths[self.source.index])
            #if self.labels is not None:
            #    self.proxies.append(pylab.plot([],[], color=color, linestyle=linestyle, linewidth=self.linewidths[self.source.index])[0])
        if self.labels is not None:
            if self.fill_colors[self.source.index] is not None:
                print self.fill_colors[self.source.index]
            elif fill:
                print self.source.index, self.line_list[self.source.index]
                if self.line_list[self.source.index] is not None:
                    conv = matplotlib.colors.ColorConverter()
                    edgecolor = linecolor
                    self.proxies.append(
                        pylab.Line2D([0, 2.5], [0, 0],
                                     linestyle=linestyle,
                                     linewidth=3,
                                     color=linecolor))
                    #facecolor=conv.to_rgba(color,alpha=1-(1-self.alphas[self.source.index])**2)
                    #self.proxies.append(pylab.Rectangle((0,0),1,1,facecolor=facecolor,edgecolor=edgecolor))#,alpha=(1-(1-self.alphas[self.source.index])**2)))
                else:
                    self.proxies.append(
                        pylab.Rectangle(
                            (0, 0),
                            1,
                            1,
                            fc=color,
                            edgecolor=color,
                            alpha=(1 -
                                   (1 - self.alphas[self.source.index])**2)))
            else:
                self.proxies.append(
                    pylab.plot(
                        [], [],
                        color=color,
                        linestyle=linestyle,
                        linewidth=self.linewidths[self.source.index])[0])

        if self.plot_points is not None:
            point_markers = ['x', '+', '^']
            for p, m in zip(self.plot_points, point_markers):
                print p, m
                pylab.plot(p[0],
                           p[1],
                           m,
                           color='k',
                           markersize=10,
                           markerfacecolor='none')

        #Do the labels
        print self.proxies, self.labels
        if self.labels is not None:
            leg = pylab.legend(self.proxies,
                               self.labels,
                               loc="upper left",
                               fontsize=13)
            leg.get_frame().set_alpha(
                0.75)  # this will make the box totally transparent
            leg.get_frame().set_edgecolor(
                'white')  # this will make the edges of the
        pylab.ylabel(r"$A_\mathrm{IA}$", fontsize=30, fontname='serif')
        pylab.xlabel(r"$b_g$", fontsize=30, fontname='serif')
        pylab.tight_layout()
        for col, text in zip(self.colors, leg.get_texts()):
            text.set_color(col)
            if col == 'pink':
                text.set_color('hotpink')
        if blind:
            pylab.xticks(visible=False)
        pylab.xticks(visible=True, fontsize=25)
        pylab.yticks(visible=True, fontsize=25)
        pylab.xlim(self.axis[0], self.axis[1])
        pylab.ylim(self.axis[2], self.axis[3])
        pylab.title('$z=1.0$', fontsize=25)
        #       pylab.subplots_adjust(top=0.95)
        x0 = [4.6]
        dx = [0.5]
        y0 = [1.77]
        pylab.errorbar(x0,
                       y0,
                       xerr=dx,
                       yerr=[0.04],
                       markersize=9.0,
                       markerfacecolor='k',
                       color='k',
                       marker='*',
                       markeredgecolor='k',
                       linestyle='none')
        #  pylab.errorbar([4.35341365],[1.80416667], xerr=7.080459e-01, yerr=1.706998e-02,color='pink',marker='o')
        #pylab.title('$\gamma \gamma + \delta_g \gamma + \delta_g\delta_g$')
        #pylab.axhline(0,color="k",alpha=0.5,ls=':')
        #pylab.axhline(5.0,color="darkviolet",lw=1, ls="--")
        #print "Plotting bounds line..."
        return filename
Ejemplo n.º 11
0
    def make_2d_plot(self, name1, name2):
          #Get the data
        x = self.reduced_col(name1)
        y = self.reduced_col(name2)


        if x.max()-x.min()==0 or y.max()-y.min()==0:
            return
        print "  (making %s vs %s)" % (name1, name2)


        #Interpolate using KDE
        try:
            n, x_axis, y_axis, like = self.smooth_likelihood(x, y)
        except np.linalg.LinAlgError:
            print "  -- these two parameters have singular covariance - probably a linear relation"
            print "Not making a 2D plot of them"
            return []

        figure,filename = self.figure("2D", name1, name2)

          #Choose levels at which to plot contours
        
        contour1=1-0.68
        contour2=1-0.95
        try: 
            level1, level2, total_mass = self._find_contours(like, x, y, n, x_axis[0], x_axis[-1], y_axis[0], y_axis[-1], contour1, contour2)
        except:
            import pdb ; pdb.set_trace()
        level0 = 1.1
        levels = [level2, level1, level0]
        #Create the figure
        fig,filename = self.figure("2D", name1, name2)
        pylab.figure(fig.number)

        #Make the plot
        #pylab.figure(figure.number, figsize=(8,7))
        keywords = self.keywords_2d()
        fill = self.options.get("fill", True)
        if self.fill_list!=None:
            fill = self.fill_list[self.source.index]
        imshow = self.imshow[self.source.index]
        #plot_points = self.options.get("plot_points", False)
        color = self.colors[self.source.index]
        linestyle = self.linestyles[self.source.index]
        if self.linecolors[self.source.index] is not None:
            linecolor=self.linecolors[self.source.index]
        else:
            linecolor=color
        print self.source.index,linecolor
        
        if self.opaque_list[self.source.index]:
            pylab.contourf(x_axis, y_axis, like.T, [level2,level0], colors=['white'])
        print "fill",self.source.index, fill

        if imshow:
            pylab.imshow(like.T, extent=(x_axis[0], x_axis[-1], y_axis[0], y_axis[-1]), aspect='auto', origin='lower', cmap=cmap_white_to_color(color))
        elif fill:
            if self.fill_colors[self.source.index] is not None:
                c=self.fill_colors[self.source.index]
                pylab.contourf(x_axis, y_axis, like.T, [level2,level0], colors=[c[0]])
                pylab.contourf(x_axis, y_axis, like.T, [level1,level0], colors=[c[1]])
            else:
                pylab.contourf(x_axis, y_axis, like.T, [level2,level0], colors=[color], alpha=self.alphas[self.source.index])
                if self.opaque_centre[self.source.index]:
                    pylab.contourf(x_axis, y_axis, like.T, [level1,level0], colors=[color])
                else:
                    pylab.contourf(x_axis, y_axis, like.T, [level1,level0], colors=[color], alpha=self.alphas[self.source.index])            
        if (not fill) or self.line_list[self.source.index]: 
            print self.source.index,linecolor
            pylab.contour(x_axis, y_axis, like.T, [level2,level1], colors=[linecolor], linestyles=linestyle, linewidths=self.linewidths[self.source.index])
            #if self.labels is not None:
            #    self.proxies.append(pylab.plot([],[], color=color, linestyle=linestyle, linewidth=self.linewidths[self.source.index])[0])
        if self.labels is not None:
            if self.fill_colors[self.source.index] is not None:
                print self.fill_colors[self.source.index]
            elif fill:
                print self.source.index,self.line_list[self.source.index]
                if self.line_list[self.source.index] is not None:                    
                    conv=matplotlib.colors.ColorConverter()
                    edgecolor=linecolor
                    facecolor=conv.to_rgba(color,alpha=1-(1-self.alphas[self.source.index])**2)
                    self.proxies.append(pylab.Rectangle((0,0),1,1,facecolor=facecolor,edgecolor=edgecolor))#,alpha=(1-(1-self.alphas[self.source.index])**2)))
                else:
                    self.proxies.append(pylab.Rectangle((0,0),1,1,fc=color,edgecolor=color,alpha=(1-(1-self.alphas[self.source.index])**2)))
            else:
                self.proxies.append(pylab.plot([],[], color=color, linestyle=linestyle, linewidth=self.linewidths[self.source.index])[0])

        if self.plot_points is not None:
            point_markers=['x','+','^']
            for p,m in zip(self.plot_points,point_markers):
                print p,m
                pylab.plot(p[0], p[1], m, color='k', markersize=10, markerfacecolor='none')

        #Do the labels
        print self.proxies,self.labels
        if self.labels is not None:
            leg=pylab.legend(self.proxies,self.labels,loc="upper right")
            leg.get_frame().set_alpha(0) # this will make the box totally transparent
            leg.get_frame().set_edgecolor('white') # this will make the edges of the 
        pylab.xlabel(self.latex(name1))
        pylab.ylabel(self.latex(name2))
        pylab.tight_layout()
        if self.axis is not None:
            pylab.axis(self.axis)
        return filename     
Ejemplo n.º 12
0
    def make_2d_plot(self, name1, name2):
          #Get the data
        x = self.reduced_col(name1)
        y = self.reduced_col(name2)


        if x.max()-x.min()==0 or y.max()-y.min()==0:
            return
        print "  (making %s vs %s)" % (name1, name2)


        #Interpolate using KDE
        try:
            n, x_axis, y_axis, like = self.smooth_likelihood(x, y)
        except np.linalg.LinAlgError:
            print "  -- these two parameters have singular covariance - probably a linear relation"
            print "Not making a 2D plot of them"
            return []

        figure,filename = self.figure("2D", name1, name2)

          #Choose levels at which to plot contours
        
        contour1=1-0.68
        contour2=1-0.95
        try: 
            level1, level2, total_mass = self._find_contours(like, x, y, n, x_axis[0], x_axis[-1], y_axis[0], y_axis[-1], contour1, contour2)
        except:
            import pdb ; pdb.set_trace()
        level0 = 1.1
        levels = [level2, level1, level0]
        #Create the figure
        fig,filename = self.figure("2D", name1, name2)
        pylab.figure(fig.number)

        #Make the plot
        #pylab.figure(figure.number, figsize=(8,7))
        keywords = self.keywords_2d()
        fill = self.options.get("fill", True)
        if self.fill_list!=None:
            fill = self.fill_list[self.source.index]
        imshow = self.imshow[self.source.index]
        #plot_points = self.options.get("plot_points", False)
        color = self.colors[self.source.index]
        linestyle = self.linestyles[self.source.index]
        if self.linecolors[self.source.index] is not None:
            linecolor=self.linecolors[self.source.index]
        else:
            linecolor=color
        print self.source.index,linecolor
        
        if self.opaque_list[self.source.index]:
            pylab.contourf(x_axis, y_axis, like.T, [level2,level0], colors=['white'])
        print "fill",self.source.index, fill

        if imshow:
            pylab.imshow(like.T, extent=(x_axis[0], x_axis[-1], y_axis[0], y_axis[-1]), aspect='auto', origin='lower', cmap=cmap_white_to_color(color))
        elif fill:
            if self.fill_colors[self.source.index] is not None:
                c=self.fill_colors[self.source.index]
                pylab.contourf(x_axis, y_axis, like.T, [level2,level0], colors=[c[0]])
                pylab.contourf(x_axis, y_axis, like.T, [level1,level0], colors=[c[1]])
            else:
                pylab.contourf(x_axis, y_axis, like.T, [level2,level0], colors=[color], alpha=self.alphas[self.source.index])
                if self.opaque_centre[self.source.index]:
                    pylab.contourf(x_axis, y_axis, like.T, [level1,level0], colors=[color])
                else:
                    pylab.contourf(x_axis, y_axis, like.T, [level1,level0], colors=[color], alpha=self.alphas[self.source.index])            
        if (not fill) or self.line_list[self.source.index]: 
            print self.source.index,linecolor
            pylab.contour(x_axis, y_axis, like.T, [level2,level1], colors=[linecolor], linestyles=linestyle, linewidths=self.linewidths[self.source.index])
            #if self.labels is not None:
            #    self.proxies.append(pylab.plot([],[], color=color, linestyle=linestyle, linewidth=self.linewidths[self.source.index])[0])
        if self.labels is not None:
            if self.fill_colors[self.source.index] is not None:
                print self.fill_colors[self.source.index]
            elif fill:
                print self.source.index,self.line_list[self.source.index]
                if self.line_list[self.source.index] is not None:                    
                    conv=matplotlib.colors.ColorConverter()
                    edgecolor=linecolor
                    self.proxies.append(pylab.Line2D([0,2.5], [0,0], linestyle=linestyle, linewidth=3, color=linecolor))
                    #facecolor=conv.to_rgba(color,alpha=1-(1-self.alphas[self.source.index])**2)
                    #self.proxies.append(pylab.Rectangle((0,0),1,1,facecolor=facecolor,edgecolor=edgecolor))#,alpha=(1-(1-self.alphas[self.source.index])**2)))
                else:
                    self.proxies.append(pylab.Rectangle((0,0),1,1,fc=color,edgecolor=color,alpha=(1-(1-self.alphas[self.source.index])**2)))
            else:
                self.proxies.append(pylab.plot([],[], color=color, linestyle=linestyle, linewidth=self.linewidths[self.source.index])[0])

        if self.plot_points is not None:
            point_markers=['x','+','^']
            for p,m in zip(self.plot_points,point_markers):
                print p,m
                pylab.plot(p[0], p[1], m, color='k', markersize=10, markerfacecolor='none')

        #Do the labels
        print self.proxies,self.labels
        if self.labels is not None:
            leg=pylab.legend(self.proxies,self.labels,loc="upper right")
            leg.get_frame().set_alpha(0) # this will make the box totally transparent
            leg.get_frame().set_edgecolor('white') # this will make the edges of the 
        pylab.xlabel(r"$S_8 \equiv \sigma_8 \left( \Omega_\mathrm{m} / 0.3 \right )^{\frac{1}{2}}$",fontsize=22)
        pylab.ylabel("$A_\mathrm{IA}$", fontsize=22)
        pylab.tight_layout()
        if blind:
            pylab.xticks(visible=False)
            pylab.yticks(visible=False)
        np.random.seed(2007)
        dx = (np.random.rand()*2 - 1.0) * (0.4-1.2)*0.1
        
         
        #pylab.xticks(np.array([0.4,0.5,0.6,0.7,0.8,0.9,1.0,1.1,1.2])+dx,["0.4","0.5","0.6","0.7",'0.8','0.9','1.0','1.1','1.2'])
        #pylab.yticks(np.array([0.6,0.7,0.8,0.9,1.0])+d
        pylab.xlim(self.axis[0], self.axis[1])
        pylab.ylim(self.axis[2], self.axis[3])
        pylab.xlim(self.axis[0], self.axis[1])
        pylab.ylim(self.axis[2], self.axis[3])
        #pylab.axhline(5.0,color="darkviolet",lw=1, ls="--")
        #print "Plotting bounds line..."
        return filename     
Ejemplo n.º 13
0
    def make_2d_plot(self, name1, name2):
        #Get the data
        x = self.reduced_col(name1)
        y = self.reduced_col(name2)

        if x.max() - x.min() == 0 or y.max() - y.min() == 0:
            return
        print "  (making %s vs %s)" % (name1, name2)

        #Interpolate using KDE
        try:
            n, x_axis, y_axis, like = self.smooth_likelihood(x, y)
        except np.linalg.LinAlgError:
            print "  -- these two parameters have singular covariance - probably a linear relation"
            print "Not making a 2D plot of them"
            return []

        figure, filename = self.figure("2D", name1, name2)

        #Choose levels at which to plot contours

        contour1 = 1 - 0.68
        contour2 = 1 - 0.95
        try:
            level1, level2, total_mass = self._find_contours(
                like, x, y, n, x_axis[0], x_axis[-1], y_axis[0], y_axis[-1],
                contour1, contour2)
        except:
            import pdb
            pdb.set_trace()
        level0 = 1.1
        levels = [level2, level1, level0]
        #Create the figure
        fig, filename = self.figure("2D", name1, name2)
        pylab.figure(fig.number)

        #Make the plot
        #pylab.figure(figure.number, figsize=(8,7))
        keywords = self.keywords_2d()
        fill = self.options.get("fill", True)
        if self.fill_list != None:
            fill = self.fill_list[self.source.index]
        imshow = self.imshow[self.source.index]
        #plot_points = self.options.get("plot_points", False)
        color = self.colors[self.source.index]
        linestyle = self.linestyles[self.source.index]
        if self.linecolors[self.source.index] is not None:
            linecolor = self.linecolors[self.source.index]
        else:
            linecolor = color
        print self.source.index, linecolor

        if self.opaque_list[self.source.index]:
            pylab.contourf(x_axis,
                           y_axis,
                           like.T, [level2, level0],
                           colors=['white'])
        print "fill", self.source.index, fill

        if imshow:
            pylab.imshow(like.T,
                         extent=(x_axis[0], x_axis[-1], y_axis[0], y_axis[-1]),
                         aspect='auto',
                         origin='lower',
                         cmap=cmap_white_to_color(color))
        elif fill:
            if self.fill_colors[self.source.index] is not None:
                c = self.fill_colors[self.source.index]
                pylab.contourf(x_axis,
                               y_axis,
                               like.T, [level2, level0],
                               colors=[c[0]])
                pylab.contourf(x_axis,
                               y_axis,
                               like.T, [level1, level0],
                               colors=[c[1]])
            else:
                pylab.contourf(x_axis,
                               y_axis,
                               like.T, [level2, level0],
                               colors=[color],
                               alpha=self.alphas[self.source.index])
                if self.opaque_centre[self.source.index]:
                    pylab.contourf(x_axis,
                                   y_axis,
                                   like.T, [level1, level0],
                                   colors=[color])
                else:
                    pylab.contourf(x_axis,
                                   y_axis,
                                   like.T, [level1, level0],
                                   colors=[color],
                                   alpha=self.alphas[self.source.index])
        if (not fill) or self.line_list[self.source.index]:
            print self.source.index, linecolor
            pylab.contour(x_axis,
                          y_axis,
                          like.T, [level2, level1],
                          colors=[linecolor],
                          linestyles=linestyle,
                          linewidths=self.linewidths[self.source.index])
            #if self.labels is not None:
            #    self.proxies.append(pylab.plot([],[], color=color, linestyle=linestyle, linewidth=self.linewidths[self.source.index])[0])
        if self.labels is not None:
            if self.fill_colors[self.source.index] is not None:
                print self.fill_colors[self.source.index]
            elif fill:
                print self.source.index, self.line_list[self.source.index]
                if self.line_list[self.source.index] is not None:
                    conv = matplotlib.colors.ColorConverter()
                    edgecolor = linecolor
                    facecolor = conv.to_rgba(
                        color,
                        alpha=1 - (1 - self.alphas[self.source.index])**2)
                    self.proxies.append(
                        pylab.Rectangle((0, 0),
                                        1,
                                        1,
                                        facecolor=facecolor,
                                        edgecolor=edgecolor)
                    )  #,alpha=(1-(1-self.alphas[self.source.index])**2)))
                else:
                    self.proxies.append(
                        pylab.Rectangle(
                            (0, 0),
                            1,
                            1,
                            fc=color,
                            edgecolor=color,
                            alpha=(1 -
                                   (1 - self.alphas[self.source.index])**2)))
            else:
                self.proxies.append(
                    pylab.plot(
                        [], [],
                        color=color,
                        linestyle=linestyle,
                        linewidth=self.linewidths[self.source.index])[0])

        if self.plot_points is not None:
            point_markers = ['x', '+', '^']
            for p, m in zip(self.plot_points, point_markers):
                print p, m
                pylab.plot(p[0],
                           p[1],
                           m,
                           color='k',
                           markersize=10,
                           markerfacecolor='none')

        #Do the labels
        print self.proxies, self.labels
        if self.labels is not None:
            leg = pylab.legend(self.proxies, self.labels, loc="upper right")
            leg.get_frame().set_alpha(
                0)  # this will make the box totally transparent
            leg.get_frame().set_edgecolor(
                'white')  # this will make the edges of the
        pylab.xlabel(self.latex(name1))
        pylab.ylabel(self.latex(name2))
        pylab.tight_layout()
        if self.axis is not None:
            pylab.axis(self.axis)
        return filename