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


Python pylab.contour函数代码示例

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


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

示例1: Contour

def Contour(X,Y,Z, label='', levels=None, cmapidx=0, colors=None, fmt='%g', lwd=1, fsz=10,
        inline=0, wire=True, cbar=True, zorder=None, markZero='', clabels=True):
    """
    Plot contour
    ============
    """
    L = None
    if levels != None:
        if not hasattr(levels, "__iter__"): # not a list or array...
            levels = linspace(Z.min(), Z.max(), levels)
    if colors==None:
        c1 = contourf (X,Y,Z, cmap=Cmap(cmapidx), levels=levels, zorder=None)
    else:
        c1 = contourf (X,Y,Z, colors=colors, levels=levels, zorder=None)
    if wire:
        c2 = contour (X,Y,Z, colors=('k'), levels=levels, linewidths=[lwd], zorder=None)
        if clabels:
            clabel (c2, inline=inline, fontsize=fsz)
    if cbar:
        cb = colorbar (c1, format=fmt)
        cb.ax.set_ylabel (label)
    if markZero:
        c3 = contour(X,Y,Z, levels=[0], colors=[markZero], linewidths=[2])
        if clabels:
            clabel(c3, inline=inline, fontsize=fsz)
开发者ID:yunpeng1,项目名称:gosl,代码行数:25,代码来源:gosl.py

示例2: plot_mcmc_results

def plot_mcmc_results(chain):
    # Pull m and b arrays out of the Markov chain.
    mm = [m for b,m in chain]
    bb = [b for b,m in chain]
    # Scatterplot of m,b posterior samples
    plt.clf()
    plt.contour(bgrid, mgrid, posterior, pdf_contour_levels(posterior))
    plt.plot(bb, mm, 'b.', alpha=0.1)
    plot_mb_setup()
    plt.show()
    
    # Histograms
    import triangle
    triangle.corner(chain, labels=['b','m'], extents=[0.99]*2)
    plt.show()
    
    # Traces
    plt.clf()
    plt.subplot(2,1,1)
    plt.plot(mm, 'k-')
    plt.ylim(mlo,mhi)
    plt.ylabel('m')
    plt.subplot(2,1,2)
    plt.plot(bb, 'k-')
    plt.ylabel('b')
    plt.ylim(blo,bhi)
    plt.show()
开发者ID:Zach4011,项目名称:StatisticalMethods,代码行数:27,代码来源:straightline_utils.py

示例3: contour

def contour(*args, **kwargs):
    """
    Make an SPH image of the given simulation and render it as contours.
    nlevels and levels are passed to pyplot's contour command.

    Other arguments are as for *image*.
    """

    import copy
    kwargs_image = copy.copy(kwargs)
    nlevels = kwargs_image.pop('nlevels',None)
    levels = kwargs_image.pop('levels',None)
    width = kwargs_image.get('width','10 kpc')
    kwargs_image['noplot']=True
    im = image(*args, **kwargs_image)
    res = im.shape

    units = kwargs_image.get('units',None)

    if isinstance(width, str) or issubclass(width.__class__, _units.UnitBase):
        if isinstance(width, str):
            width = _units.Unit(width)
        sim = args[0]
        width = width.in_units(sim['pos'].units, **sim.conversion_context())

    width = float(width)
    x,y = np.meshgrid(np.linspace(-width/2,width/2,res[0]),np.linspace(-width/2,width/2,res[0]))

    p.contour(x,y,im,nlevels=nlevels,levels=levels)
开发者ID:migueldvb,项目名称:pynbody,代码行数:29,代码来源:sph.py

示例4: contour

def contour(list):
    xrange = numpy.arange(-5, 5, 0.05)
    yrange = numpy.arange(-5, 5, 0.05)

    grid = matrix([[indicator(x, y, list) for y in yrange] for x in xrange])
    pylab.contour(xrange, yrange, grid, (-1.0, 0.0, 1.0), colors=('red', 'black', 'blue'), linewidths=(1, 3, 1))
    pylab.show()
开发者ID:bonnywong,项目名称:DD2431,代码行数:7,代码来源:main.py

示例5: doSubplot

        def doSubplot(multiplier=1.0, layout=(-1, -1)):
            if time_sec < 16200:
                xs, ys = xs_1, ys_1
                domain_bounds = bounds_1sthalf
                grid = grid_1
            else:
                xs, ys = xs_2, ys_2
                domain_bounds = bounds_2ndhalf
                grid = grid_2

            try:
                mo = ARPSModelObsFile("%s/%s/KCYS%03dan%06d" % (base_path, exp, min_ens, time_sec))
            except AssertionError:
                mo = ARPSModelObsFile("%s/%s/KCYS%03dan%06d" % (base_path, exp, min_ens, time_sec), mpi_config=(2, 12))
            except:
                print "Can't load reflectivity ..."
                mo = {'Z':np.zeros((1, 255, 255), dtype=np.float32)}

            pylab.contour(xs, ys, wind[exp]['w'][wdt][domain_bounds], levels=np.arange(2, 102, 2), styles='-', colors='k')
            pylab.contour(xs, ys, wind[exp]['w'][wdt][domain_bounds], levels=np.arange(-100, 0, 2), styles='--', colors='k')

            pylab.quiver(xs[thin], ys[thin], wind[exp]['u'][wdt][domain_bounds][thin], wind[exp]['v'][wdt][domain_bounds][thin])

            pylab.contourf(xs, ys, mo['Z'][0][domain_bounds], levels=np.arange(10, 85, 5), cmap=NWSRef, zorder=-10)

            grid.drawPolitical(scale_len=10)

            row, col = layout
            if col == 1:
                pylab.text(-0.075, 0.5, exp_names[exp], transform=pylab.gca().transAxes, rotation=90, ha='center', va='center', size=12 * multiplier)
开发者ID:tsupinie,项目名称:research,代码行数:30,代码来源:plot_reflectivity.py

示例6: plot_debug

def plot_debug(result):
    import pylab
    from pylab import contour, grid, show
    contours = (70.9/22.4, 70.9/22.4*3, 70.9/22.4*20)
    contour(result, contours)
    grid(True)
    show()
开发者ID:striges,项目名称:gapuff,代码行数:7,代码来源:model_class.py

示例7: test_masking

def test_masking():
    xi, yi = 20*random.rand(2, 100)
    hi = exp( -(xi-10.)**2/10.0 -(yi-10.)**2/5.0)
    h = grid.extrap_xy_to_grid(xi, yi, hi)
    pl.contour(grid.x_rho, grid.y_rho, h)
    print h
    pl.show()
开发者ID:jmsole-METEOSIM,项目名称:pyroms,代码行数:7,代码来源:grid.py

示例8: visualize_fits

def visualize_fits(fitsfile, figname, colorbar = False) :
    '''Saves fitsfile contents as an image, <figname>.png'''
    pl.figure()
    pl.contour(get_fits_obj(fitsfile))
    if colorbar:
        pl.colorbar()
    pl.savefig(figname+'.png')
开发者ID:cavestruz,项目名称:StrongCNN,代码行数:7,代码来源:read_fits.py

示例9: plot_haxby

def plot_haxby(activation, title):
    z = 25

    fig = pl.figure(figsize=(4, 5.4))
    fig.subplots_adjust(bottom=0., top=1., left=0., right=1.)
    pl.axis('off')
    # pl.title('SVM vectors')
    pl.imshow(np.rot90(mean_img[:, 4:58, z]), cmap=pl.cm.gray,
              interpolation='nearest')
    pl.imshow(np.rot90(activation[:, 4:58, z]), cmap=pl.cm.hot,
              interpolation='nearest')

    mask_house = nibabel.load(h.mask_house[0]).get_data()
    mask_face = nibabel.load(h.mask_face[0]).get_data()

    pl.contour(np.rot90(mask_house[:, 4:58, z].astype(np.bool)), contours=1,
            antialiased=False, linewidths=4., levels=[0],
            interpolation='nearest', colors=['blue'])

    pl.contour(np.rot90(mask_face[:, 4:58, z].astype(np.bool)), contours=1,
            antialiased=False, linewidths=4., levels=[0],
            interpolation='nearest', colors=['limegreen'])

    p_h = Rectangle((0, 0), 1, 1, fc="blue")
    p_f = Rectangle((0, 0), 1, 1, fc="limegreen")
    pl.legend([p_h, p_f], ["house", "face"])
    pl.title(title, x=.05, ha='left', y=.90, color='w', size=28)
开发者ID:GaelVaroquaux,项目名称:frontiers2013,代码行数:27,代码来源:plot_haxby_decoding.py

示例10: main

def main():
    print("Running main method.")
    print("")
    
    # Generate the datapoints and plot them.
    classA, classB = gen_datapoints_helper()

    kernels = [LINEAR, POLYNOMIAL, RADIAL_BASIS, SIGMOID]
    for k in kernels:
        pylab.figure()
        pylab.title(kernel_name(k))
        pylab.plot([p[0] for p in classA],
                    [p[1] for p in classA],
                    'bo')
        pylab.plot([p[0] for p in classB],
                    [p[1] for p in classB],
                    'ro')

        # Add the sets together and shuffle them around.
        datapoints = gen_datapoints_from_classes(classA, classB)

        t= train(datapoints, k)

        # Plot the decision boundaries.
        xr=numpy.arange(-4, 4, 0.05)
        yr=numpy.arange(-4, 4, 0.05)
        grid=matrix([[indicator(t, x, y, k) for y in yr] for x in xr])
        pylab.contour(xr, yr, grid, (-1.0, 0.0, 1.0), colors=('red', 'black', 'blue'), linewidths=(1, 3, 1))

    # Now that we are done we show the ploted datapoints and the decision
    # boundary.
    pylab.show()
开发者ID:kalleand,项目名称:machinelearning,代码行数:32,代码来源:lab2.py

示例11: main

def main():
    import pylab
    
    # Create the gaussian data
    Xin, Yin = pylab.mgrid[0:201, 0:201]
    data = gaussian(3, 100, 100, 20, 40)(Xin, Yin) + np.random.random(Xin.shape)
    
    pylab.matshow(data, cmap='gist_rainbow')
    
    params = fitgaussian(data)
    fit = gaussian(*params)
    
    pylab.contour(fit(*pylab.indices(data.shape)), cmap='copper')
    ax = pylab.gca()
    (height, x, y, width_x, width_y) = params
    
    pylab.text(0.95, 0.05, """
    x : %.1f
    y : %.1f
    width_x : %.1f
    width_y : %.1f""" %(x, y, width_x, width_y),
            fontsize=16, horizontalalignment='right',
            verticalalignment='bottom', transform=ax.transAxes)
    
    pylab.show()
开发者ID:seddon-software,项目名称:python3-examples,代码行数:25,代码来源:_02_fit_gaussian.py

示例12: multiple_optima

def multiple_optima(gene_number=937, resolution=80, model_restarts=10, seed=10000, max_iters=300, optimize=True, plot=True):
    """
    Show an example of a multimodal error surface for Gaussian process
    regression. Gene 939 has bimodal behaviour where the noisy mode is
    higher.
    """

    # Contour over a range of length scales and signal/noise ratios.
    length_scales = np.linspace(0.1, 60., resolution)
    log_SNRs = np.linspace(-3., 4., resolution)

    try:import pods
    except ImportError:
        print 'pods unavailable, see https://github.com/sods/ods for example datasets'
        return
    data = pods.datasets.della_gatta_TRP63_gene_expression(data_set='della_gatta',gene_number=gene_number)
    # data['Y'] = data['Y'][0::2, :]
    # data['X'] = data['X'][0::2, :]

    data['Y'] = data['Y'] - np.mean(data['Y'])

    lls = GPy.examples.regression._contour_data(data, length_scales, log_SNRs, GPy.kern.RBF)
    if plot:
        pb.contour(length_scales, log_SNRs, np.exp(lls), 20, cmap=pb.cm.jet)
        ax = pb.gca()
        pb.xlabel('length scale')
        pb.ylabel('log_10 SNR')

        xlim = ax.get_xlim()
        ylim = ax.get_ylim()

    # Now run a few optimizations
    models = []
    optim_point_x = np.empty(2)
    optim_point_y = np.empty(2)
    np.random.seed(seed=seed)
    for i in range(0, model_restarts):
        # kern = GPy.kern.RBF(1, variance=np.random.exponential(1.), lengthscale=np.random.exponential(50.))
        kern = GPy.kern.RBF(1, variance=np.random.uniform(1e-3, 1), lengthscale=np.random.uniform(5, 50))

        m = GPy.models.GPRegression(data['X'], data['Y'], kernel=kern)
        m.likelihood.variance = np.random.uniform(1e-3, 1)
        optim_point_x[0] = m.rbf.lengthscale
        optim_point_y[0] = np.log10(m.rbf.variance) - np.log10(m.likelihood.variance);

        # optimize
        if optimize:
            m.optimize('scg', xtol=1e-6, ftol=1e-6, max_iters=max_iters)

        optim_point_x[1] = m.rbf.lengthscale
        optim_point_y[1] = np.log10(m.rbf.variance) - np.log10(m.likelihood.variance);

        if plot:
            pb.arrow(optim_point_x[0], optim_point_y[0], optim_point_x[1] - optim_point_x[0], optim_point_y[1] - optim_point_y[0], label=str(i), head_length=1, head_width=0.5, fc='k', ec='k')
        models.append(m)

    if plot:
        ax.set_xlim(xlim)
        ax.set_ylim(ylim)
    return m # (models, lls)
开发者ID:Arthurkorn,项目名称:GPy,代码行数:60,代码来源:regression.py

示例13: 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

示例14: contourFromFunction

def contourFromFunction(XYfunction,plotPoints=100,\
			xrange=None,yrange=None,numContours=20,alpha=1.0, contourLines=None):
	"""
	Given a 2D function, plots constant contours over the given
	range.  If the range is not given, the current plotting
	window range is used.
	"""
	
	# set up x and y ranges
	currentAxis = pylab.axis()
	if xrange is not None:
		xvalues = pylab.linspace(xrange[0],xrange[1],plotPoints)
	else:
		xvalues = pylab.linspace(currentAxis[0],currentAxis[1],plotPoints)
	if yrange is not None:
		yvalues = pylab.linspace(yrange[0],yrange[1],plotPoints)
	else:
		yvalues = pylab.linspace(currentAxis[2],currentAxis[3],plotPoints)
	
	#coordArray = _coordinateArray2D(xvalues,yvalues)
	# add extra dimension to this to make iterable?
	# bug here!  need to fix for contour plots
	z = map( lambda y: map(lambda x: XYfunction(x,y), xvalues), yvalues)
	if contourLines:
		pylab.contour(xvalues,yvalues,z,contourLines,alpha=alpha)
	else:
		pylab.contour(xvalues,yvalues,z,numContours,alpha=alpha)
开发者ID:yanjiun,项目名称:SloppyScalingYJversion,代码行数:27,代码来源:PlotEnsemble.py

示例15: polarmap_contours

def polarmap_contours(polarmap):  # Example docstring
   """
   Identifies the real and imaginary contours in a polar map.  Returns
   the real and imaginary contours as 2D vertex arrays together with
   the pairs of contours known to intersect. The coordinate system is
   normalized so x and y coordinates range from zero to one.
   Contour plotting requires origin='upper' for consistency with image
   coordinate system.
   """
   # Convert to polar and normalise
   normalized_polar = normalize_polar_channel(polarmap)
   figure_handle = plt.figure()
   # Real component
   re_contours_plot = plt.contour(normalized_polar.real, levels=[0], origin='upper')
   re_path_collections = re_contours_plot.collections[0]
   re_contour_paths = re_path_collections.get_paths()
   # Imaginary component
   im_contours_plot = plt.contour(normalized_polar.imag, levels=[0], origin='upper')
   im_path_collections = im_contours_plot.collections[0]
   im_contour_paths = im_path_collections.get_paths()
   plt.close(figure_handle)
   intersections = [ (re_ind, im_ind)
                     for (re_ind, re_path) in enumerate(re_contour_paths)
                     for (im_ind, im_path) in enumerate(im_contour_paths)
                    if im_path.intersects_path(re_path)]

   (ydim, xdim) = polarmap.shape
   # Contour vertices  0.5 pixel inset. Eg. (0,0)-(48,48)=>(0.5, 0.5)-(47.5, 47.5)
   # Returned values will not therefore reach limits of 0.0 and 1.0
   re_contours =  [remove_path_duplicates(re_path.vertices) / [ydim, xdim] \
                       for re_path in re_contour_paths]
   im_contours =  [remove_path_duplicates(im_path.vertices) / [ydim, xdim] \
                       for im_path in im_contour_paths]
   return (re_contours,  im_contours, intersections)
开发者ID:antolikjan,项目名称:fast_inh_paper,代码行数:34,代码来源:pinwheel_analysis.py


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