Python matplotlib.mlab 模块,griddata() 实例源码

我们从Python开源项目中,提取了以下10个代码示例,用于说明如何使用matplotlib.mlab.griddata()

项目:CAAPR    作者:Stargrazer82301    | 项目源码 | 文件源码
def interpolate_apertures(self, aperture_centers, aperture_means):

        """
        This function ...
        :param aperture_centers:
        :param aperture_means:
        :return:
        """

        # Inform the user
        log.info("Interpolating between the mean values of each aperture to fill the sky frame ...")

        x_values = np.array([center.x for center in aperture_centers])
        y_values = np.array([center.y for center in aperture_centers])

        x_ticks = np.arange(0, self.frame.xsize, 1)
        y_ticks = np.arange(0, self.frame.ysize, 1)
        z_grid = mlab.griddata(x_values, y_values, aperture_means, x_ticks, y_ticks)

        # Set the sky frame
        self.sky = Frame(z_grid)

    # -----------------------------------------------------------------
项目:CAAPR    作者:Stargrazer82301    | 项目源码 | 文件源码
def interpolate_apertures(self, aperture_centers, aperture_means):

        """
        This function ...
        :param aperture_centers:
        :param aperture_means:
        :return:
        """

        # Inform the user
        log.info("Interpolating between the mean values of each aperture to fill the sky frame ...")

        x_values = np.array([center.x for center in aperture_centers])
        y_values = np.array([center.y for center in aperture_centers])

        x_ticks = np.arange(0, self.frame.xsize, 1)
        y_ticks = np.arange(0, self.frame.ysize, 1)
        z_grid = mlab.griddata(x_values, y_values, aperture_means, x_ticks, y_ticks)

        # Set the sky frame
        self.sky = Frame(z_grid)

    # -----------------------------------------------------------------
项目:CAAPR    作者:Stargrazer82301    | 项目源码 | 文件源码
def plot_interpolated(self, aperture_centers, aperture_means):

        """
        This function ...
        :param aperture_centers:
        :param aperture_means:
        :return:
        """

        x_values = np.array([center.x for center in aperture_centers])
        y_values = np.array([center.y for center in aperture_centers])

        x_ticks = np.arange(0, self.frame.xsize, 1)
        y_ticks = np.arange(0, self.frame.ysize, 1)
        z_grid = mlab.griddata(x_values, y_values, aperture_means, x_ticks, y_ticks)

        self.sky = Frame(z_grid)

        from matplotlib.backends import backend_agg as agg
        from matplotlib import cm

        # plot
        #fig = Figure()  # create the figure
        fig = plt.figure()
        agg.FigureCanvasAgg(fig)  # attach the rasterizer
        ax = fig.add_subplot(1, 1, 1)  # make axes to plot on
        ax.set_title("Interpolated Contour Plot of Experimental Data")
        ax.set_xlabel("X")
        ax.set_ylabel("Y")

        cmap = cm.get_cmap("hot")  # get the "hot" color map
        contourset = ax.contourf(x_ticks, y_ticks, z_grid, 10, cmap=cmap)

        cbar = fig.colorbar(contourset)
        cbar.set_ticks([0, 100])
        fig.axes[-1].set_ylabel("Z")  # last axes instance is the colorbar

        plt.show()

    # -----------------------------------------------------------------
项目:CAAPR    作者:Stargrazer82301    | 项目源码 | 文件源码
def plot_interpolated(self, aperture_centers, aperture_means):

        """
        This function ...
        :param aperture_centers:
        :param aperture_means:
        :return:
        """

        x_values = np.array([center.x for center in aperture_centers])
        y_values = np.array([center.y for center in aperture_centers])

        x_ticks = np.arange(0, self.frame.xsize, 1)
        y_ticks = np.arange(0, self.frame.ysize, 1)
        z_grid = mlab.griddata(x_values, y_values, aperture_means, x_ticks, y_ticks)

        self.sky = Frame(z_grid)

        from matplotlib.backends import backend_agg as agg
        from matplotlib import cm

        # plot
        #fig = Figure()  # create the figure
        fig = plt.figure()
        agg.FigureCanvasAgg(fig)  # attach the rasterizer
        ax = fig.add_subplot(1, 1, 1)  # make axes to plot on
        ax.set_title("Interpolated Contour Plot of Experimental Data")
        ax.set_xlabel("X")
        ax.set_ylabel("Y")

        cmap = cm.get_cmap("hot")  # get the "hot" color map
        contourset = ax.contourf(x_ticks, y_ticks, z_grid, 10, cmap=cmap)

        cbar = fig.colorbar(contourset)
        cbar.set_ticks([0, 100])
        fig.axes[-1].set_ylabel("Z")  # last axes instance is the colorbar

        plt.show()

    # -----------------------------------------------------------------
项目:OTC3D    作者:tiffanyts    | 项目源码 | 文件源码
def contour(self,title='',cbartitle = '',model=[], zmax = None, zmin = None, filename = None, resolution = 1, unit_str = '', bar = True):
        """ Returns a figure with contourplot of 2D spatial data. Insert filename to save the figure as an image. Increase resolution to increase detail of interpolated data (<1 to decrease)"""

        font = {'weight' : 'medium',
                'size'   : 22}

        xi = np.linspace(min(self.data.x), max(self.data.x),len(set(self.data.x))*resolution)
        yi = np.linspace(min(self.data.y), max(self.data.y),len(set(self.data.y))*resolution)


        zi = ml.griddata(self.data.x, self.data.y, self.data.v.interpolate(), xi, yi,interp='linear')

        fig = plt.figure()
        plt.rc('font', **font)
        plt.title(title)
        plt.contour(xi, yi, zi, 15, linewidths = 0, cmap=plt.cm.bone)
        plt.pcolormesh(xi, yi, zi, cmap = plt.get_cmap('rainbow'),vmax = zmax, vmin = zmin)
        if bar: cbar = plt.colorbar(); cbar.ax.set_ylabel(cbartitle)

        plt.absolute_import
        try:
            vertices = [(vertex.X(), vertex.Y()) for vertex in pyliburo.py3dmodel.fetch.vertex_list_2_point_list(pyliburo.py3dmodel.fetch.topos_frm_compound(model)["vertex"])]
            shape = patches.PathPatch(Path(vertices), facecolor='white', lw=0)
            plt.gca().add_patch(shape)
        except TypeError:
            pass
        plt.show()

        try:
            fig.savefig(filename)
        except TypeError:
            return fig

#    def plot_along_line(self,X,Y, tick_list):
#        V = self.data.v
#        plt.plot(heights, SVFs_can, label='Canyon')
项目:MicapsDataDraw    作者:flashlxy    | 项目源码 | 文件源码
def UpdateData(self, products, micapsfile):
        self.UpdateExtents(products)

        extents = products.picture.extents
        xmax = extents.xmax
        xmin = extents.xmin
        ymax = extents.ymax
        ymin = extents.ymin

        path = products.map.clipborders[0].path

        if path is not None:
            self.AddPoints(self.x, self.y, self.z, path)

        # self.CreateArray()
        self.X = np.linspace(xmin, xmax, micapsfile.contour.grid[0])
        self.Y = np.linspace(ymin, ymax, micapsfile.contour.grid[1])
        # x = self.data['lon']
        # y = self.data['lat']
        # z = self.data['zvalue']
        self.Z = griddata(self.x, self.y, self.z, self.X, self.Y, 'nn')
        self.X, self.Y = np.meshgrid(self.X, self.Y)

        self.min = min(self.z)
        self.max = max(self.z)
        self.distance = micapsfile.contour.step
        self.min = math.floor(self.min / self.distance) * self.distance
        self.max = math.ceil(self.max / self.distance) * self.distance
        # ??????legend?????????? ?????????
        self.UpdatePinLegendValue(micapsfile)
项目:crypto-forcast    作者:7yl4r    | 项目源码 | 文件源码
def plotRibbons(dta, saveFigName, index):
    """
    creates ribbon-plot one-ribbon-at-a-time
    """
    fig=gcf()
    ax=fig.gca(projection='3d')
    width=5  # assumes two indicies aren't too close together...
    y_min=0  # assumes given index (season len) is between 0-100
    y_max=100

    y=dta
    x=sorted(list(range(1,len(y)+1))*2)
    a=[index,index+width]*len(y)
    b=list(itertools.chain(*zip(y,y)))
    xi=np.linspace(min(x),max(x))
    yi=np.linspace(min(a),max(a))
    X,Y=np.meshgrid(xi,yi)
    Z=griddata(x,a,b,xi,yi, interp='linear')

    # to plot w/ y-axis colormapped:
    # colors =plt.cm.spectral( (Y-Y.min())/float((Y-Y.min()).max()) )
    colors =plt.cm.spectral( (Y-y_min)/float(y_max-y_min) )
    ax.plot_surface(X,Y,Z ,facecolors=colors, linewidth=0, shade=False )

    # to plot w/ z-axis colormapped:
    # ax.plot_surface(X,Y,Z,rstride=50,cstride=1,cmap='Spectral')

    ax.set_zlim3d(np.min(Z),np.max(Z))
    ax.grid(False)
    ax.w_xaxis.pane.set_visible(False)
    ax.w_yaxis.pane.set_visible(False)
    ax.w_zaxis.pane.set_color('gainsboro')
    # ax.set_title('Molecular spectra')
    # ax.set_xlim3d(0,23)
    # ax.set_xticks([1.6735,6.8367,12.0000,17.1633,22.3265])
    # ax.set_xticklabels(['350','400','450','500','550'])
    # ax.set_xlabel('Wavelength (nm)')
    # ax.set_yticks([0.5,1.5,2.5,3.5,4.5,5.5,6.5,7.5,8.5])
    # ax.set_yticklabels(['1','2','3','4','5','6','7','8'])
    # ax.set_ylabel('Spectrum')
    # ax.set_zlim3d(0,2)
    # ax.set_zlabel('Absorbance')
    plt.savefig(str(saveFigName))
项目:CAAPR    作者:Stargrazer82301    | 项目源码 | 文件源码
def plot_map(self):

        """
        This function ...
        :return:
        """

        # Inform the user
        log.info("Plotting a map of the heating fraction of the unevolved stellar population for a face-on view of the galaxy ...")

        # Determine the path to the plot file
        path = fs.join(self.analysis_heating_path, "map.pdf")

        plt.figure()

        x = np.ma.MaskedArray(self.absorptions["X coordinate of cell center"], mask=self.mask).compressed()
        y = np.ma.MaskedArray(self.absorptions["Y coordinate of cell center"], mask=self.mask).compressed()
        z = self.heating_fractions_compressed

        #plt.pcolormesh(x, y, z, cmap='RdBu', vmin=0.0, vmax=1.0)

        from matplotlib import mlab

        x_ticks = x
        y_ticks = y

        z_grid = mlab.griddata(x, y, z, x, y)

        from matplotlib.backends import backend_agg as agg
        from matplotlib import cm

        # plot
        # fig = Figure()  # create the figure
        fig = plt.figure()
        agg.FigureCanvasAgg(fig)  # attach the rasterizer
        ax = fig.add_subplot(1, 1, 1)  # make axes to plot on
        ax.set_title("Interpolated Contour Plot of Experimental Data")
        ax.set_xlabel("X")
        ax.set_ylabel("Y")

        cmap = cm.get_cmap("hot")  # get the "hot" color map
        contourset = ax.contourf(x_ticks, y_ticks, z_grid, 10, cmap=cmap)

        plt.savefig(path)
        plt.close()

    # -----------------------------------------------------------------
项目:icnn    作者:locuslab    | 项目源码 | 文件源码
def adam_plot(self, func, obs, hist):
        hist['act'] = np.array(hist['act']).T
        hist['f'] = np.array(hist['f']).T
        hist['g'] = np.array(hist['g']).T
        if self.dimA == 1:
            xs = np.linspace(-1.+1e-8, 1.-1e-8, 100)
            ys = [func(obs[[0],:], [[xi]])[0] for xi in xs]
            fig = plt.figure()
            plt.plot(xs, ys)
            plt.plot(hist['act'][0,0,:], hist['f'][0,:], label='Adam')
            plt.legend()
            fname = os.path.join(FLAGS.outdir, 'adamPlt.png')
            print("Saving Adam plot to {}".format(fname))
            plt.savefig(fname)
            plt.close(fig)
        elif self.dimA == 2:
            assert(False)
        else:
            xs = npr.uniform(-1., 1., (5000, self.dimA))
            ys = np.array([func(obs[[0],:], [xi])[0] for xi in xs])
            epi = np.hstack((xs, ys))
            pca = PCA(n_components=2).fit(epi)
            W = pca.components_[:,:-1]
            xs_proj = xs.dot(W.T)
            fig = plt.figure()

            X = Y = np.linspace(xs_proj.min(), xs_proj.max(), 100)
            Z = griddata(xs_proj[:,0], xs_proj[:,1], ys.ravel(),
                         X, Y, interp='linear')

            plt.contourf(X, Y, Z, 15)
            plt.colorbar()

            adam_x = hist['act'][:,0,:].T
            adam_x = adam_x.dot(W.T)
            plt.plot(adam_x[:,0], adam_x[:,1], label='Adam', color='k')
            plt.legend()

            fname = os.path.join(FLAGS.outdir, 'adamPlt.png')
            print("Saving Adam plot to {}".format(fname))
            plt.savefig(fname)
            plt.close(fig)
项目:POWER    作者:pennelise    | 项目源码 | 文件源码
def grid(x, y, z, resX=100, resY=100):
    """"Convert 3 column data to matplotlib grid
    Credit: Elyase of Stackoverflow."""
    xi = np.linspace(min(x), max(x), resX)
    yi = np.linspace(min(y), max(y), resY)
    Z = griddata(x, y, z, xi, yi,interp='linear')
    X, Y = np.meshgrid(xi, yi)
    return X, Y, Z