Python mpl_toolkits.axes_grid1 模块,AxesGrid() 实例源码

我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用mpl_toolkits.axes_grid1.AxesGrid()

项目:face_detection    作者:chintak    | 项目源码 | 文件源码
def plot_weight_matrix(Z, outname, save=True):
    num = Z.shape[0]
    fig = plt.figure(1, (80, 80))
    fig.subplots_adjust(left=0.05, right=0.95)
    grid = AxesGrid(fig, (1, 4, 2),  # similar to subplot(142)
                    nrows_ncols=(int(np.ceil(num / 10.)), 10),
                    axes_pad=0.04,
                    share_all=True,
                    label_mode="L",
                    )

    for i in range(num):
        im = grid[i].imshow(Z[i, :, :, :].mean(
            axis=0), cmap='gray')
    for i in range(grid.ngrids):
        grid[i].axis('off')

    for cax in grid.cbar_axes:
        cax.toggle_label(False)
    if save:
        fig.savefig(outname, bbox_inches='tight')
        fig.clear()
项目:ugali    作者:DarkEnergySurvey    | 项目源码 | 文件源码
def plot3(self):
        fig = pylab.figure(figsize=(8,4))
        axes = AxesGrid(fig, 111,nrows_ncols = (1, 3),axes_pad=0.1,
                        cbar_mode='each',cbar_pad=0,cbar_size='5%',
                        cbar_location='top',share_all=True)
        for ax in axes:
            ax.get_xaxis().set_visible(False)
            ax.get_yaxis().set_visible(False)

        self.drawImage(axes[0])
        self.drawTS(axes[1])
        #self.drawStellarDensity(axes[1])
        self.drawMask(axes[2])
        return fig,axes
项目:ugali    作者:DarkEnergySurvey    | 项目源码 | 文件源码
def plot4(self):
        fig = pylab.figure(figsize=(8,8))
        axes = AxesGrid(fig, 111,nrows_ncols = (2, 2),axes_pad=0.25,
                        cbar_mode='each',cbar_pad=0,cbar_size='5%',
                        share_all=True,aspect=True,
                        label_mode='L')

        #fig,axes = plt.subplots(2,2)
        #axes = axes.flatten()

        #for ax in axes:
        #    ax.get_xaxis().set_visible(False)
        #    ax.get_yaxis().set_visible(False)

        #plt.sca(axes[0]); self.drawImage(axes[0])
        #plt.sca(axes[1]); self.drawStellarDensity(axes[1])
        #plt.sca(axes[2]); self.drawMask(axes[2])
        #plt.sca(axes[3]); self.drawTS(axes[3])
        try: plt.sca(axes[0]); self.drawImage()
        except IOError as e: logger.warn(str(e))

        plt.sca(axes[1]); self.drawStellarDensity()
        plt.sca(axes[2]); self.drawMask()
        try: plt.sca(axes[3]); self.drawTS()
        except IOError as e: logger.warn(str(e))

        axes[0].set_xlim(self.radius,-self.radius)
        axes[0].set_ylim(-self.radius,self.radius)

        return fig,axes
项目:ugali    作者:DarkEnergySurvey    | 项目源码 | 文件源码
def plotKernel(kernel):
    fig = plt.figure()
    axes = AxesGrid(fig, 111, nrows_ncols = (1,1),
                    cbar_mode='none',cbar_pad=0,cbar_size='5%',
                    cbar_location='top', share_all=True)
    drawKernel(axes[0],kernel)
项目:ugali    作者:DarkEnergySurvey    | 项目源码 | 文件源码
def plotDistance(self):
        filename = self.config.mergefile
        logger.debug("Opening %s..."%filename)
        f = pyfits.open(filename)
        pixels,values = f[1].data['PIXEL'],2*f[1].data['LOG_LIKELIHOOD']
        if values.ndim == 1: values = values.reshape(-1,1)
        distances = f[2].data['DISTANCE_MODULUS']
        if distances.ndim == 1: distances = distances.reshape(-1,1)
        ts_map = healpy.UNSEEN * numpy.ones(healpy.nside2npix(self.nside))

        ndim = len(distances)
        nrows = int(numpy.sqrt(ndim))
        ncols = ndim // nrows + (ndim%nrows > 0)

        fig = pylab.figure()
        axes  = AxesGrid(fig, 111, nrows_ncols = (nrows, ncols),axes_pad=0,
                         label_mode='1', cbar_mode='single',cbar_pad=0,cbar_size='5%',
                         share_all=True,add_all=False)

        images = []
        for i,val in enumerate(values.T):
            ts_map[pixels] = val

            im = healpy.gnomview(ts_map,**self.gnom_kwargs)
            pylab.close()
            images.append(im)
        data = numpy.array(images); mask = (data == healpy.UNSEEN)
        images = numpy.ma.array(data=data,mask=mask)
        vmin = numpy.ma.min(images)
        vmax = numpy.ma.max(images)

        for i,val in enumerate(values.T):
            ax = axes[i]
            im = ax.imshow(images[i],origin='bottom',vmin=vmin,vmax=vmax)
            ax.cax.colorbar(im)

            #ax.annotate(r"$\mu = %g$"%distances[i],**self.label_kwargs)
            ax.annotate(r"$d = %.0f$ kpc"%mod2dist(distances[i]),**self.label_kwargs)
            ax.axis["left"].major_ticklabels.set_visible(False) 
            ax.axis["bottom"].major_ticklabels.set_visible(False) 
            fig.add_axes(ax)
            fig.add_axes(ax.cax)
        return fig,axes