当前位置: 首页>>代码示例>>Python>>正文


Python pylab.pcolormesh函数代码示例

本文整理汇总了Python中pylab.pcolormesh函数的典型用法代码示例。如果您正苦于以下问题:Python pcolormesh函数的具体用法?Python pcolormesh怎么用?Python pcolormesh使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了pcolormesh函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: i5

def i5():
    # griddata
    r, dr = 10, 4
    dth = dr/(1.0*r)
    
    rr = linspace(r,r+dr,15)
    th = linspace(-0.5*dth,0.5*dth,16)
    R,TH = make_grid(rr,th)
    X,Y = R*cos(TH),R*sin(TH)
    Z = ff(X,Y)
    points = grid_to_points(X,Y)
    values = grid_to_points(Z)
    
    xfine = linspace(r,r+dr,50)
    yfine = linspace(-0.5*dr,0.5*dr,51)
    XF, YF = make_grid(xfine, yfine)
    desired_points = grid_to_points(XF, YF)

    # Only 'nearest' seems to work
    # 'linear' and 'cubic' just give fill value
    desired_values = scipy.interpolate.griddata(points, values, desired_points, method='nearest', fill_value=1.0)
    ZF = desired_values.reshape(XF.shape)
    
    pl.clf()
    pl.pcolormesh(XF, YF, ZF)
    pl.colorbar()
    return ZF
开发者ID:gnovak,项目名称:plevpy,代码行数:27,代码来源:gsn.py

示例2: i6

def i6():
    # Rbf: this works great except that somewhat weird stuff happens
    # when you're off the grid.
    r, dr = 10, 4
    dth = dr/(1.0*r)
    
    rr = linspace(r,r+dr,25)
    th = linspace(-0.5*dth,0.5*dth,26)
    R,TH = make_grid(rr,th)
    X,Y = R*cos(TH),R*sin(TH)
    Z = ff(X,Y)
    xlist, ylist, zlist = X.ravel(), Y.ravel(), Z.ravel()
    
    # function, epsilon, smooth, norm, 
    fint = scipy.interpolate.Rbf(xlist, ylist, zlist )

    xfine = linspace(-10+r,r+dr+10,99)
    yfine = linspace(-10-0.5*dr,10+0.5*dr,101)
    XF, YF = make_grid(xfine, yfine)
    ZF = fint(XF, YF)
    
    pl.clf()
    pl.pcolormesh(XF, YF, ZF)
    pl.colorbar()
    return ZF
开发者ID:gnovak,项目名称:plevpy,代码行数:25,代码来源:gsn.py

示例3: i1

def i1():
    # interp2d
    # This does not seem to work.  It also does not seem to honor
    # bounds_error or fill_value

    #xx = linspace(0,2*pi,39)
    #yy = linspace(-2,2,41)
    xx = linspace(0,2*pi,12)
    yy = linspace(-2,2,11)
    X,Y = make_grid(xx,yy)
    Z = ff(X,Y)

    # Note that in this use, xx,yy and 1d, Z is 2d.  
    # The output shapes are 
    # fint: ()   ()   => (1,)
    # fint: (n,) ()   => (n,)
    # fint: ()   (m,) => (1,m)
    # fint: (n,) (m,) => (n,m)

    fint = scipy.interpolate.interp2d(xx,yy, Z)

    xfine = linspace(0.0,2*pi,99)
    yfine = linspace(-2,2,101)
    XF, YF = make_grid(xfine, yfine)
    ZF = fint(xfine,yfine).transpose()

    pl.clf()
    pl.pcolormesh(XF,YF,ZF)
    pl.colorbar()
开发者ID:gnovak,项目名称:plevpy,代码行数:29,代码来源:gsn.py

示例4: i2

def i2():
    # interp2d -- do it on a structured gird, but use calling
    # convention for unstructured grid.

    xx = linspace(0,2*pi,15)
    yy = linspace(-2,2,14)
    X,Y = make_grid(xx,yy)
    Z = ff(X,Y)

    # The output shapes are 
    # fint: ()   ()   => (1,)
    # fint: (n,) ()   => (n,)
    # fint: ()   (m,) => (1,m)
    # fint: (n,) (m,) => (n,m)
    # 
    # Linear interpolation is all messed up. Cant get sensible results.
    # Cubic seems extremely sensitive to the exact number of data points.
    # Doesn't respect bounds_error
    # Doesn't respect fill_value
    # Doesn't respect copy
    fint = scipy.interpolate.interp2d(X,Y,Z, kind='quintic')
    
    xfine = linspace(-2,2*pi+2,99)
    yfine = linspace(-4,4,101)
    XF, YF = make_grid(xfine, yfine)
    # NB -- TRANSPOSE HERE!
    ZF = fint(xfine,yfine).transpose()

    pl.clf()
    pl.pcolormesh(XF, YF, ZF)
    pl.colorbar()
开发者ID:gnovak,项目名称:plevpy,代码行数:31,代码来源:gsn.py

示例5: logRegress

def logRegress(X,Y):

	scores = []
	for train_index, test_index in kf:
		X_train, X_test = X[train_index], X[test_index]
		y_train, y_test = Y[train_index], Y[test_index]
		logModel = linear_model.LogisticRegression()
		logModel.fit(X_train,y_train)
		scores.append(logModel.score(X_test, y_test))
		
		print "Scores" , scores

		x_min, x_max = X[:, 0].min() - .5, X[:, 0].max() + .5
		y_min, y_max = X[:, 1].min() - .5, X[:, 1].max() + .5
		xx, yy = np.meshgrid(np.arange(x_min, x_max, h), np.arange(y_min, y_max, h))
		Z = logreg.predict(np.c_[xx.ravel(), yy.ravel()])

		# Put the result into a color plot
		Z = Z.reshape(xx.shape)
		pl.figure(1, figsize=(4, 3))
		pl.pcolormesh(xx, yy, Z, cmap=pl.cm.Paired)

		# Plot also the training points
		pl.scatter(X[:, 0], X[:, 1], c=Y, edgecolors='k', cmap=pl.cm.Paired)
		pl.xlabel('Sepal length')
		pl.ylabel('Sepal width')

		pl.xlim(xx.min(), xx.max())
		pl.ylim(yy.min(), yy.max())
		pl.xticks(())
		pl.yticks(())

		pl.show()
开发者ID:liljonnystyle,项目名称:safetyword,代码行数:33,代码来源:GodsPipe2.py

示例6: the_plot

def the_plot():
    x,y = linspace(0,2*pi,100), linspace(-2,2,100)
    X,Y = make_grid(x,y)
    Z = ff(X,Y)
    pl.clf()
    pl.pcolormesh(X,Y,Z)
    pl.colorbar()
开发者ID:gnovak,项目名称:plevpy,代码行数:7,代码来源:gsn.py

示例7: main

def main(plot=True):

    # Setup grid
    g = 4
    nx, ny = 200, 50
    Lx, Ly = 26, 26/4

    (x, y), (dx, dy) = ghosted_grid([nx, ny], [Lx, Ly], 0)

    # monkey patch the velocity
    uc = MultiFab(sizes=[nx, ny], n_ghost=4, dof=2)
    uc.validview[0] = (y > Ly / 3) * (2 * Ly / 3 > y)
    uc.validview[1] = np.sin(2 * pi * x / Lx) * .3 / (2 * pi / Lx)
    # state.u = np.random.rand(*x.shape)

    tad = BarotropicSolver()
    tad.geom.dx = dx
    tad.geom.dy = dx

    dt = min(dx, dy) / 4

    if plot:
        import pylab as pl
        pl.ion()

    for i, (t, uc) in enumerate(steps(tad.onestep, uc, dt, [0.0, 10000 * dt])):
        if i % 100 == 0:
            if plot:
                pl.clf()
                pl.pcolormesh(uc.validview[0])
                pl.colorbar()
                pl.pause(.01)
开发者ID:nbren12,项目名称:gnl,代码行数:32,代码来源:barotropic.py

示例8: plot_results_with_hyperplane

def plot_results_with_hyperplane(clf, clf_name, df, plt_nmbr):
    x_min, x_max = df.x.min() - .5, df.x.max() + .5
    y_min, y_max = df.y.min() - .5, df.y.max() + .5

    # step between points. i.e. [0, 0.02, 0.04, ...]
    step = .02
    # to plot the boundary, we're going to create a matrix of every possible point
    # then label each point as a wolf or cow using our classifier
    xx, yy = np.meshgrid(np.arange(x_min, x_max, step), np.arange(y_min, y_max, step))
    Z = clf.predict(np.c_[xx.ravel(), yy.ravel()])
    # this gets our predictions back into a matrix
    Z = Z.reshape(xx.shape)

    # create a subplot (we're going to have more than 1 plot on a given image)
    pl.subplot(2, 2, plt_nmbr)
    # plot the boundaries
    pl.pcolormesh(xx, yy, Z, cmap=pl.cm.Paired)

    # plot the wolves and cows
    for animal in df.animal.unique():
        pl.scatter(df[df.animal==animal].x,
                   df[df.animal==animal].y,
                   marker=animal,
                   label="cows" if animal=="x" else "wolves",
                   color='black',
                   c=df.animal_type, cmap=pl.cm.Paired)
    pl.title(clf_name)
    pl.legend(loc="best")
开发者ID:glamp,项目名称:yaksis,代码行数:28,代码来源:farmer.py

示例9: _make_logp_histogram

def _make_logp_histogram(points, logp, nbins, rangeci, weights, cbar):
    from numpy import (ones_like, searchsorted, linspace, cumsum, diff, 
        sort, argsort, array, hstack, log10, exp)
    if weights == None: weights = ones_like(logp)
    edges = linspace(rangeci[0],rangeci[1],nbins+1)
    idx = searchsorted(points, edges)
    weightsum = cumsum(weights)
    heights = diff(weightsum[idx])/weightsum[-1]  # normalized weights

    import pylab
    vmin,vmax,cmap = cbar
    cmap_steps = linspace(vmin,vmax,cmap.N+1)
    bins = [] # marginalized maximum likelihood
    for h,s,e,xlo,xhi in zip(heights,idx[:-1],idx[1:],edges[:-1],edges[1:]):
        if s == e: continue
        pv = -logp[s:e]
        pidx = argsort(pv)
        pw = weights[s:e][pidx]
        x = array([xlo,xhi],'d')
        y = hstack((0,cumsum(pw)))  
        z = pv[pidx][:,None]
        # centerpoint, histogram height, maximum likelihood for each bin
        bins.append(((xlo+xhi)/2,y[-1],exp(vmin-z[0])))
        if len(z) > cmap.N:
           # downsample histogram bar according to number of colors
           pidx = searchsorted(z[1:-1].flatten(), cmap_steps)
           if pidx[-1] < len(z)-1: pidx = hstack((pidx,-1))
           y,z = y[pidx],z[pidx]
        pylab.pcolormesh(x,y,z,vmin=vmin,vmax=vmax,hold=True,cmap=cmap)
        # Draw bars around each histogram bin
        #pylab.plot([xlo,xlo,xhi,xhi],[y[0],y[-1],y[-1],y[0]],'-k',linewidth=0.1,hold=True)
    centers,height,maxlikelihood = array(bins).T
    pylab.plot(centers, maxlikelihood*max(height), '-g', hold=True)
开发者ID:ScottSWu,项目名称:bumps,代码行数:33,代码来源:views.py

示例10: load_data

    def load_data(self):
        self.input_file = self.get_input()

        if self.input_file is None:
            print "No input file selected. Exiting..."
            import sys
            sys.exit(0)

        self.nc = NC(self.input_file)
        nc = self.nc

        self.x = np.array(nc.variables['x'][:], dtype=np.double)
        self.y = np.array(nc.variables['y'][:], dtype=np.double)
        self.z = np.array(np.squeeze(nc.variables['usurf'][:]), dtype=np.double)
        self.thk = np.array(np.squeeze(nc.variables['thk'][:]), dtype=np.double)

        self.mask = dbg.initialize_mask(self.thk)
        print "Mask initialization: done"

        plt.figure(1)
        plt.pcolormesh(self.x, self.y, self.mask)
        plt.contour(self.x, self.y, self.z, colors='black')
        plt.axis('tight')
        plt.axes().set_aspect('equal')
        plt.show()
开发者ID:ckhroulev,项目名称:dbg-playground,代码行数:25,代码来源:pism_regional.py

示例11: compute_mask

    def compute_mask(self):
        import matplotlib.nxutils as nx

        if self.pts is not None:
            def correct_mask(mask, x, y, pts):
                    for j in range(y.size):
                        for i in range(x.size):
                            if mask[j,i] > 0:
                                if nx.pnpoly(x[i], y[j], pts):
                                    mask[j,i] = 2
                                else:
                                    mask[j,i] = 1

            correct_mask(self.mask, self.x, self.y, self.pts)

        dbg.upslope_area(self.x, self.y, self.z, self.mask)
        print "Drainage basin computation: done"
        self.mask_computed = True

        plt.figure(1)
        plt.pcolormesh(self.x, self.y, self.mask)
        plt.contour(self.x, self.y, self.z, colors='black')
        plt.axis('tight')
        plt.axes().set_aspect('equal')
        plt.show()
开发者ID:ckhroulev,项目名称:dbg-playground,代码行数:25,代码来源:pism_regional.py

示例12: plotRadTilt

def plotRadTilt(plot_data, plot_cmaps, plot_titles, grid, file_name, base_ref=None):
    subplot_base = 220
    n_plots = 4

    xs, ys, gs_x, gs_y, map = grid

    pylab.figure(figsize=(12,12))
    pylab.subplots_adjust(left=0.02, right=0.98, top=0.98, bottom=0.02, wspace=0.04)

    for plot in range(n_plots):
        pylab.subplot(subplot_base + plot + 1)
        cmap, vmin, vmax = plot_cmaps[plot]
        cmap.set_under("#ffffff", alpha=0.0)

        pylab.pcolormesh(xs - gs_x / 2, ys - gs_y / 2, plot_data[plot] >= -90, vmin=0, vmax=1, cmap=mask_cmap)

        pylab.pcolormesh(xs - gs_x / 2, ys - gs_y / 2, plot_data[plot], vmin=vmin, vmax=vmax, cmap=cmap)
        pylab.colorbar()

        if base_ref is not None:
            pylab.contour(xs, ys, base_ref, levels=[10.], colors='k', lw=0.5)

#       if plot == 0:
#           pylab.contour(xs, ys, refl_88D[:, :, 0], levels=np.arange(10, 80, 10), colors='#808080', lw=0.5)

#       pylab.plot(radar_x, radar_y, 'ko')

        pylab.title(plot_titles[plot])

        drawPolitical(map)

    pylab.savefig(file_name)
    pylab.close()

    return
开发者ID:tsupinie,项目名称:research,代码行数:35,代码来源:read_enkf_rad.py

示例13: plotGridPref

def plotGridPref(gridscore, clfName, obj , metric = 'roc_auc'):
    ''' Plot Grid Performance
    '''
    # data_path = data_path+obj+'/'+clfName+'_opt.h5'
    # f=hp.File(data_path, 'r')
    # gridscore = f['grids_score'].value
    # Get numblocks
    CV = np.unique(gridscore["i_CV"])
    folds = np.unique(gridscore["i_fold"])
    numblocks = len(CV) * len(folds)
    paramNames = gridscore.dtype.fields.keys()
    paramNames.remove("mean_validation_score")
    paramNames.remove("std")
    paramNames.remove("i_CV")
    paramNames.remove("i_fold")
    score = gridscore["mean_validation_score"]
    std = gridscore["std"]
    newgridscore = gridscore[paramNames]
    num_params = len(paramNames)
    ### get index of hit ###
    hitindex = []
    n_iter = len(score)/numblocks
    for k in range(numblocks):
        hit0index = np.argmax(score[k*n_iter: (k+1)*n_iter])
        hitindex.append(k*n_iter+hit0index )

    for m in range(num_params-1):
        i = paramNames[m]
        x = newgridscore[i]
        for n in range(m+1, num_params):
        # for j in list(set(paramNames)- set([i])):
            j = paramNames[n]
            y = newgridscore[j]
            compound = [x,y]
            # Only plot heat map if dtype of all elements of x, y are int or float
            if [True]* len(compound)== map(lambda t: np.issubdtype(t.dtype,  np.float) or np.issubdtype(t.dtype, np.int), compound):
                gridsize = 50
                fig = pl.figure()
                points = np.vstack([x,y]).T
                #####Construct MeshGrids##########
                xnew = np.linspace(max(x), min(x), gridsize)
                ynew = np.linspace(max(y), min(y), gridsize)
                X, Y = np.meshgrid(xnew, ynew)
                #####Interpolate Z on top of MeshGrids#######
                Z = griddata(points, score, (X, Y), method = "cubic", tol = 1e-2)
                z_min = min(score)
                z_max = max(score)
                pl.pcolormesh(X,Y,Z, cmap='RdBu', vmin=z_min, vmax=z_max)
                pl.axis([x.min(), x.max(), y.min(), y.max()])
                pl.xlabel(i, fontsize = 30)
                pl.ylabel(j, fontsize = 30)
                cb = pl.colorbar()
                cb.set_label(metric, fontsize = 30)
                ##### Mark the "hit" points #######
                hitx = x[hitindex]
                hity = y[hitindex]
                pl.plot(hitx, hity, 'rx')
                # Save the plot
                save_path = plot_path +obj+'/'+ clfName +'_' +metric+'_'+ i +'_'+ j+'.pdf'
                fig.savefig(save_path)
开发者ID:rexshihaoren,项目名称:MSPrediction-Python,代码行数:60,代码来源:MSPred.py

示例14: __call__

    def __call__(self, n):
        if len(self.f.shape) == 3:
            # f = f[x,v,t], 2 dim in phase space
            ft = self.f[n,:,:]
            pylab.pcolormesh(self.X, self.V, ft.T, cmap = 'jet')
            pylab.colorbar()
            pylab.clim(0,0.38) # for Landau test case
            pylab.grid()
            pylab.axis([self.xmin, self.xmax, self.ymin, self.ymax])
            pylab.xlabel('$x$', fontsize = 18)
            pylab.ylabel('$v$', fontsize = 18)
            pylab.title('$N_x$ = %d, $N_v$ = %d, $t$ = %2.1f' % (self.x.N, self.v.N, self.it*self.t.width))
            pylab.savefig(self.path + self.filename)
            pylab.clf()
            return None

        if len(self.f.shape) == 2:
            # f = f[x], 1 dim in phase space
            ft = self.f[n,:]
            pylab.plot(self.x.gridvalues,ft,'ob')
            pylab.grid()
            pylab.axis([self.xmin, self.xmax, self.ymin, self.ymax])
            pylab.xlabel('$x$', fontsize = 18)
            pylab.ylabel('$f(x)$', fontsize = 18)
            pylab.savefig(self.path + self.filename)
            return None
开发者ID:dsirajud,项目名称:IPython-notebooks,代码行数:26,代码来源:plots.py

示例15: plotLL

def plotLL(fname='out4.npy'):
    plt.figure()
    h= np.linspace(0,1,21)
    g= np.linspace(0,1,21)
    m=np.linspace(0,2,21)
    d=np.linspace(0,2,21)
    out=np.load(fname)
    print np.nanmax(out),np.nanmin(out)
    rang=np.nanmax(out)-np.nanmin(out)
    maxloc= np.squeeze(np.array((np.nanmax(out)==out).nonzero()))
    H,G=np.meshgrid(h,g)
    print maxloc
    for mm in range(m.size/2):
        for dd in range(d.size/2):
            plt.subplot(10,10,(9-mm)*10+dd+1)
            plt.pcolormesh(h,g,out[:,:,mm*2,dd*2].T,
                           vmax=np.nanmax(out),vmin=np.nanmax(out)-rang/4.)
            plt.gca().set_xticks([])
            plt.gca().set_yticks([])
            if mm==maxloc[2]/2 and dd==maxloc[3]/2:
                plt.plot(h[maxloc[0]],g[maxloc[1]],'ow',ms=8)
            if dd==0:
                print mm,dd
                plt.ylabel('%.1f'%m[mm*2])
            if mm==0: plt.xlabel('%.1f'%d[dd*2])
    plt.title(fname[:6])
开发者ID:simkovic,项目名称:toolbox,代码行数:26,代码来源:Model.py


注:本文中的pylab.pcolormesh函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。