Python matplotlib.pyplot 模块,clabel() 实例源码

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

项目:PorousMediaLab    作者:biogeochemistry    | 项目源码 | 文件源码
def saturation_index_countour(lab, elem1, elem2, Ks, labels=False):
    plt.figure()
    plt.title('Saturation index %s%s' % (elem1, elem2))
    resoluion = 100
    n = math.ceil(lab.time.size / resoluion)
    plt.xlabel('Time')
    z = np.log10((lab.species[elem1]['concentration'][:, ::n] + 1e-8) * (
        lab.species[elem2]['concentration'][:, ::n] + 1e-8) / lab.constants[Ks])
    lim = np.max(abs(z))
    lim = np.linspace(-lim - 0.1, +lim + 0.1, 51)
    X, Y = np.meshgrid(lab.time[::n], -lab.x)
    plt.xlabel('Time')
    CS = plt.contourf(X, Y, z, 20, cmap=ListedColormap(sns.color_palette(
        "RdBu_r", 101)), origin='lower', levels=lim, extend='both')
    if labels:
        plt.clabel(CS, inline=1, fontsize=10, colors='w')
    # cbar = plt.colorbar(CS)
    if labels:
        plt.clabel(CS, inline=1, fontsize=10, colors='w')
    cbar = plt.colorbar(CS)
    plt.ylabel('Depth')
    ax = plt.gca()
    ax.ticklabel_format(useOffset=False)
    cbar.ax.set_ylabel('Saturation index %s%s' % (elem1, elem2))
    return ax
项目:PorousMediaLab    作者:biogeochemistry    | 项目源码 | 文件源码
def contour_plot_of_rates(lab, r, labels=False, last_year=False):
    plt.figure()
    plt.title('{}'.format(r))
    resoluion = 100
    n = math.ceil(lab.time.size / resoluion)
    if last_year:
        k = n - int(1 / lab.dt)
    else:
        k = 1
    z = lab.estimated_rates[r][:, k - 1:-1:n]
    # lim = np.max(np.abs(z))
    # lim = np.linspace(-lim - 0.1, +lim + 0.1, 51)
    X, Y = np.meshgrid(lab.time[k::n], -lab.x)
    plt.xlabel('Time')
    CS = plt.contourf(X, Y, z, 20, cmap=ListedColormap(
        sns.color_palette("Blues", 51)))
    if labels:
        plt.clabel(CS, inline=1, fontsize=10, colors='w')
    cbar = plt.colorbar(CS)
    plt.ylabel('Depth')
    ax = plt.gca()
    ax.ticklabel_format(useOffset=False)
    cbar.ax.set_ylabel('Rate %s [M/V/T]' % r)
    return ax
项目:PorousMediaLab    作者:biogeochemistry    | 项目源码 | 文件源码
def contour_plot_of_delta(lab, element, labels=False, last_year=False):
    plt.figure()
    plt.title('Rate of %s consumption/production' % element)
    resoluion = 100
    n = math.ceil(lab.time.size / resoluion)
    if last_year:
        k = n - int(1 / lab.dt)
    else:
        k = 1
    z = lab.species[element]['rates'][:, k - 1:-1:n]
    lim = np.max(np.abs(z))
    lim = np.linspace(-lim - 0.1, +lim + 0.1, 51)
    X, Y = np.meshgrid(lab.time[k:-1:n], -lab.x)
    plt.xlabel('Time')
    CS = plt.contourf(X, Y, z, 20, cmap=ListedColormap(sns.color_palette(
        "RdBu_r", 101)), origin='lower', levels=lim, extend='both')
    if labels:
        plt.clabel(CS, inline=1, fontsize=10, colors='w')
    cbar = plt.colorbar(CS)
    plt.ylabel('Depth')
    ax = plt.gca()
    ax.ticklabel_format(useOffset=False)
    cbar.ax.set_ylabel('Rate of %s change $[\Delta/T]$' % element)
    return ax
项目:iota    作者:amaneureka    | 项目源码 | 文件源码
def Pcolor(xs, ys, zs, pcolor=True, contour=False, **options):
    """Makes a pseudocolor plot.

    xs:
    ys:
    zs:
    pcolor: boolean, whether to make a pseudocolor plot
    contour: boolean, whether to make a contour plot
    options: keyword args passed to pyplot.pcolor and/or pyplot.contour
    """
    _Underride(options, linewidth=3, cmap=matplotlib.cm.Blues)

    X, Y = np.meshgrid(xs, ys)
    Z = zs

    x_formatter = matplotlib.ticker.ScalarFormatter(useOffset=False)
    axes = pyplot.gca()
    axes.xaxis.set_major_formatter(x_formatter)

    if pcolor:
        pyplot.pcolormesh(X, Y, Z, **options)

    if contour:
        cs = pyplot.contour(X, Y, Z, **options)
        pyplot.clabel(cs, inline=1, fontsize=10)
项目:ThinkX    作者:AllenDowney    | 项目源码 | 文件源码
def Pcolor(xs, ys, zs, pcolor=True, contour=False, **options):
    """Makes a pseudocolor plot.

    xs:
    ys:
    zs:
    pcolor: boolean, whether to make a pseudocolor plot
    contour: boolean, whether to make a contour plot
    options: keyword args passed to plt.pcolor and/or plt.contour
    """
    _Underride(options, linewidth=3, cmap=matplotlib.cm.Blues)

    X, Y = np.meshgrid(xs, ys)
    Z = zs

    x_formatter = matplotlib.ticker.ScalarFormatter(useOffset=False)
    axes = plt.gca()
    axes.xaxis.set_major_formatter(x_formatter)

    if pcolor:
        plt.pcolormesh(X, Y, Z, **options)

    if contour:
        cs = plt.contour(X, Y, Z, **options)
        plt.clabel(cs, inline=1, fontsize=10)
项目:computationalphysics_N2014301020131    作者:Nucleus2014    | 项目源码 | 文件源码
def plot_2d(self,ax1,ax2,x1,x2,y1,y2):    # give 2d plot of potential and electric field
        self.x=linspace(x1,x2,self.n)
        self.y=linspace(y2,y1,self.n)
        self.x,self.y=meshgrid(self.x,self.y)

        cs=ax1.contour(self.x,self.y,self.V)
        plt.clabel(cs, inline=1, fontsize=10)
        ax1.set_title('Equipotential lines',fontsize=18)
        ax1.set_xlabel('x (m)',fontsize=14)
        ax1.set_ylabel('y (m)',fontsize=14)

        for j in range(1,self.n-1,1):
            for i in range(1,self.n-1,1):
                ax2.arrow(self.x[j][i],self.y[j][i],self.Ex[j][i]/40,self.Ey[j][i]/40,fc='k', ec='k')             
        ax2.set_xlim(-1.,1.)
        ax2.set_ylim(-1.,1.)
        ax2.set_title('Electric field',fontsize=18)
        ax2.set_xlabel('x (m)',fontsize=14)
        ax2.set_ylabel('y (m)',fontsize=14)
项目:computationalphysics_N2014301020131    作者:Nucleus2014    | 项目源码 | 文件源码
def plot_2d(self,ax1,ax2,x1,x2,y1,y2):    # give 2d plot of potential and electric field
        self.x=linspace(x1,x2,self.n)
        self.y=linspace(y2,y1,self.n)
        self.x,self.y=meshgrid(self.x,self.y)

        cs=ax1.contour(self.x,self.y,self.V)
        plt.clabel(cs, inline=1, fontsize=10)
        ax1.set_title('Equipotential lines',fontsize=18)
        ax1.set_xlabel('x (m)',fontsize=14)
        ax1.set_ylabel('y (m)',fontsize=14)

        for j in range(1,self.n-1,1):
            for i in range(1,self.n-1,1):
                ax2.arrow(self.x[j][i],self.y[j][i],self.Ex[j][i]/40,self.Ey[j][i]/40,fc='k', ec='k')             
        ax2.set_xlim(-1.,1.)
        ax2.set_ylim(-1.,1.)
        ax2.set_title('Electric field',fontsize=18)
        ax2.set_xlabel('x (m)',fontsize=14)
        ax2.set_ylabel('y (m)',fontsize=14)
项目:computationalphysics_N2014301020131    作者:Nucleus2014    | 项目源码 | 文件源码
def plot_2d(self,ax1,ax2,x1,x2,y1,y2):     # give 2d plot of potential and electric field
        self.x=linspace(x1,x2,self.n)
        self.y=linspace(y2,y1,self.n)
        self.x,self.y=meshgrid(self.x,self.y)

        cs=ax1.contour(self.x,self.y,self.V)
        plt.clabel(cs, inline=1, fontsize=10)
        ax1.set_title('Equipotential lines',fontsize=18)
        ax1.set_xlabel('x (m)',fontsize=14)
        ax1.set_ylabel('y (m)',fontsize=14)

        for j in range(1,self.n-1,1):
            for i in range(1,self.n-1,1):
                ax2.arrow(self.x[j][i],self.y[j][i],self.Ex[j][i]/40,self.Ey[j][i]/40,fc='k', ec='k')             
        ax2.set_xlim(-1.,1.)
        ax2.set_ylim(-1.,1.)
        ax2.set_title('Electric field',fontsize=18)
        ax2.set_xlabel('x (m)',fontsize=14)
        ax2.set_ylabel('y (m)',fontsize=14)
项目:pyqha    作者:mauropalumbo75    | 项目源码 | 文件源码
def plot_Etot_contour(celldmsx,nmesh=(50,50,50),fittype="quadratic",ibrav=4,a=None):
    """
    This function makes a countour plot with matplotlib of Ex(celldmsx) fitted results. 
    The plot type depends on ibrav.
    """

    from .minutils import calculate_fitted_points_anis

    if a==None:
        return

    fig = plt.figure() 
    ax = fig.add_subplot(1, 1, 1)  # create an axes object in the figure

    if (ibrav==4):
        celldmsxdense, Edensefitted = calculate_fitted_points_anis(celldmsx,nmesh,fittype,ibrav,a)
        Xd = np.zeros((nmesh[0],nmesh[2]))
        Yd = np.zeros((nmesh[0],nmesh[2]))
        Zd = np.zeros((nmesh[0],nmesh[2]))
        for i in range(0,nmesh[0]):
            for j in range(0,nmesh[2]): 
                index = i*nmesh[0]+j
                Xd[i,j] = celldmsxdense[index,0]
                Yd[i,j] = celldmsxdense[index,2]
                Zd[i,j] = Edensefitted[index]

        CS = ax.contour(Xd, Yd, Zd)
        plt.clabel(CS, inline=1, fontsize=10)

        CS.ax.set_xlabel("a (a.u.)")
        CS.ax.set_ylabel("c (a.u.)")
        plt.show()

    return fig
项目:PorousMediaLab    作者:biogeochemistry    | 项目源码 | 文件源码
def contour_plot(lab, element, labels=False, days=False, last_year=False):
    plt.figure()
    plt.title(element + ' concentration')
    resoluion = 100
    n = math.ceil(lab.time.size / resoluion)
    if last_year:
        k = n - int(1 / lab.dt)
    else:
        k = 1
    if days:
        X, Y = np.meshgrid(lab.time[k::n] * 365, -lab.x)
        plt.xlabel('Time')
    else:
        X, Y = np.meshgrid(lab.time[k::n], -lab.x)
        plt.xlabel('Time')
    z = lab.species[element]['concentration'][:, k - 1:-1:n]
    CS = plt.contourf(X, Y, z, 51, cmap=ListedColormap(
        sns.color_palette("Blues", 51)), origin='lower')
    if labels:
        plt.clabel(CS, inline=1, fontsize=10, colors='w')
    cbar = plt.colorbar(CS)
    plt.ylabel('Depth')
    ax = plt.gca()
    ax.ticklabel_format(useOffset=False)
    cbar.ax.set_ylabel('%s [M/V]' % element)
    if element == 'Temperature':
        plt.title('Temperature contour plot')
        cbar.ax.set_ylabel('Temperature, C')
    if element == 'pH':
        plt.title('pH contour plot')
        cbar.ax.set_ylabel('pH')
    return ax
项目:arm-gcm-diagnostics    作者:ARM-DOE    | 项目源码 | 文件源码
def annual_cycle_taylor_diagram(parameter):
    """Calculate annual cycle climatology"""
    variables = parameter.variables
    seasons = parameter.season
    output_path = parameter.output_path

    var_longname = [ varid_longname[x] for x in variables]
    for j, variable in enumerate(variables):
        obs_data = genfromtxt(output_path+'/metrics/'+variable+'_obs_annual_cycle_std_corr.csv')
        test_data = genfromtxt(output_path+'/metrics/'+variable+'_test_annual_cycle_std_corr.csv')
        mmm_data = genfromtxt(output_path+'/metrics/'+variable+'_mmm_annual_cycle_std_corr.csv')
        cmip_data = genfromtxt(output_path+'/metrics/'+variable+'_cmip_annual_cycle_std_corr.csv')
        mod_num = cmip_data.shape[0]


        fig = plt.figure(figsize=(8,8))
        refstd = obs_data[0]
        dia = TaylorDiagram(refstd, fig=fig,rect=111, label="Reference")

        # Add samples to Taylor diagram
        for i,(stddev,corrcoef) in enumerate(cmip_data):
            dia.add_sample(stddev, corrcoef, marker='.',ms=10, c='grey')

        dia.add_sample(test_data[0], test_data[1],marker='.',ms=15, c='red',label='MOD')
        dia.add_sample(mmm_data[0], mmm_data[1],marker='.',ms=15, c='b',label='MMM')

        # Add RMS contours, and label them
        contours = dia.add_contours(colors='0.5')
        plt.clabel(contours, inline=1, fontsize=10)
        plt.title(var_longname[j])

        # Add a figure legend
        fig.legend([dia.samplePoints[0],dia.samplePoints[-2],dia.samplePoints[-1]] ,
                   [ p.get_label() for p in [dia.samplePoints[0],dia.samplePoints[-2],dia.samplePoints[-1]] ],
                   numpoints=1,  loc='upper right',prop={'size':10})
#        np.savetxt(basedir+'metrics/'+vas[va_ind]+'_'+mod+'std_corr.csv',mod_sample,fmt='%.3f')
        fig.savefig(output_path+'/figures/'+variable+'_annual_cycle_taylor_diagram.png')
        plt.close('all')
项目:trump-weather    作者:JulianNorton    | 项目源码 | 文件源码
def plotBoundary(mytheta, myX, myy, mylambda=0.):
    """
    Function to plot the decision boundary for arbitrary theta, X, y, lambda value
    Inside of this function is feature mapping, and the minimization routine.
    It works by making a grid of x1 ("xvals") and x2 ("yvals") points,
    And for each, computing whether the hypothesis classifies that point as
    True or False. Then, a contour is drawn with a built-in pyplot function.
    """
    theta, mincost = optimizeRegularizedTheta(mytheta,myX,myy,mylambda)
    xvals = np.linspace(-1,1.5,50)
    yvals = np.linspace(-1,1.5,50)
    zvals = np.zeros((len(xvals),len(yvals)))
    for i in range(len(xvals)):
        for j in range(len(yvals)):
            myfeaturesij = mapFeature(np.array([xvals[i]]),np.array([yvals[j]]))
            zvals[i][j] = np.dot(theta,myfeaturesij.T)
    zvals = zvals.transpose()

    u, v = np.meshgrid( xvals, yvals )
    mycontour = plt.contour( xvals, yvals, zvals, [0])
    #Kind of a hacky way to display a text on top of the decision boundary
    myfmt = { 0:'Lambda = %d'%mylambda}
    plt.clabel(mycontour, inline=1, fontsize=15, fmt=myfmt)
    plt.title("Decision Boundary")


#Build a figure showing contours for various values of regularization parameter, lambda
#It shows for lambda=0 we are overfitting, and for lambda=100 we are underfitting
项目:MicapsDataDraw    作者:flashlxy    | 项目源码 | 文件源码
def DrawContourAndMark(contour, x, y, z, level, clipborder, patch, m):

        # ??????? ------ ??????????

        if contour.contour['visible']:

            matplotlib.rcParams['contour.negative_linestyle'] = 'dashed'
            if contour.contour['colorline']:
                CS1 = m.contour(x, y, z, levels=level,
                                linewidths=contour.contour['linewidth'])
            else:
                CS1 = m.contour(x, y, z, levels=level,
                                linewidths=contour.contour['linewidth'], colors=contour.contour['linecolor'])

            # ?????????
            if contour.contourlabel['visible']:
                CS2 = plt.clabel(CS1, inline=1, fmt=contour.contourlabel['fmt'],
                                 inline_spacing=contour.contourlabel['inlinespacing'],
                                 fontsize=contour.contourlabel['fontsize'],
                                 colors=contour.contourlabel['fontcolor'])

            # ???????????
            if clipborder.path is not None and clipborder.using:
                for collection in CS1.collections:
                    # collection.set_clip_on(True)
                    collection.set_clip_path(patch)

                for text in CS2:
                    if not clipborder.path.contains_point(text.get_position()):
                        text.remove()
            # print(CS2)
项目:computational_physics_N2014301020117    作者:yukangnineteen    | 项目源码 | 文件源码
def plot_contour(self): 
        X, Y = np.meshgrid(np.arange(-1.00, 1.01, 2./(len(self.lattice_in) - 1)), np.arange(-1.00, 1.01, 2./(len(self.lattice_in) - 1)))
        plt.figure(figsize = (8,8))
        CS = plt.contour(X, Y, self.lattice_in, 19)
        plt.clabel(CS, inline=1, fontsize=10)
        plt.title('Electric potential near two metal plates')
        #plt.show()
        return 0
项目:iota    作者:amaneureka    | 项目源码 | 文件源码
def Contour(obj, pcolor=False, contour=True, imshow=False, **options):
    """Makes a contour plot.

    d: map from (x, y) to z, or object that provides GetDict
    pcolor: boolean, whether to make a pseudocolor plot
    contour: boolean, whether to make a contour plot
    imshow: boolean, whether to use pyplot.imshow
    options: keyword args passed to pyplot.pcolor and/or pyplot.contour
    """
    try:
        d = obj.GetDict()
    except AttributeError:
        d = obj

    _Underride(options, linewidth=3, cmap=matplotlib.cm.Blues)

    xs, ys = zip(*d.keys())
    xs = sorted(set(xs))
    ys = sorted(set(ys))

    X, Y = np.meshgrid(xs, ys)
    func = lambda x, y: d.get((x, y), 0)
    func = np.vectorize(func)
    Z = func(X, Y)

    x_formatter = matplotlib.ticker.ScalarFormatter(useOffset=False)
    axes = pyplot.gca()
    axes.xaxis.set_major_formatter(x_formatter)

    if pcolor:
        pyplot.pcolormesh(X, Y, Z, **options)
    if contour:
        cs = pyplot.contour(X, Y, Z, **options)
        pyplot.clabel(cs, inline=1, fontsize=10)
    if imshow:
        extent = xs[0], xs[-1], ys[0], ys[-1]
        pyplot.imshow(Z, extent=extent, **options)
项目:ThinkX    作者:AllenDowney    | 项目源码 | 文件源码
def Contour(obj, pcolor=False, contour=True, imshow=False, **options):
    """Makes a contour plot.

    d: map from (x, y) to z, or object that provides GetDict
    pcolor: boolean, whether to make a pseudocolor plot
    contour: boolean, whether to make a contour plot
    imshow: boolean, whether to use plt.imshow
    options: keyword args passed to plt.pcolor and/or plt.contour
    """
    try:
        d = obj.GetDict()
    except AttributeError:
        d = obj

    _Underride(options, linewidth=3, cmap=matplotlib.cm.Blues)

    xs, ys = zip(*d.keys())
    xs = sorted(set(xs))
    ys = sorted(set(ys))

    X, Y = np.meshgrid(xs, ys)
    func = lambda x, y: d.get((x, y), 0)
    func = np.vectorize(func)
    Z = func(X, Y)

    x_formatter = matplotlib.ticker.ScalarFormatter(useOffset=False)
    axes = plt.gca()
    axes.xaxis.set_major_formatter(x_formatter)

    if pcolor:
        plt.pcolormesh(X, Y, Z, **options)
    if contour:
        cs = plt.contour(X, Y, Z, **options)
        plt.clabel(cs, inline=1, fontsize=10)
    if imshow:
        extent = xs[0], xs[-1], ys[0], ys[-1]
        plt.imshow(Z, extent=extent, **options)
项目:GPS    作者:golsun    | 项目源码 | 文件源码
def show_2D_GPSA(raw, GPSA_data_list, 
    key_x='axis0', key_y='axis1',
    clim=None, cmap='jet', 
    mutiplier=1.0,
    Z_cut=None,
    Z_contour=([],[]),
    ):

    x = raw[key_x]
    y = raw[key_y]
    Z = raw['mixture fraction']

    xx = sorted(list(set(x)))
    yy = sorted(list(set(y)))

    n_x = len(xx)
    n_y = len(yy)

    print 'n_x = '+str(n_x)
    print 'n_y = '+str(n_y)

    if n_x*n_y == 0:
        print 'cannot build as n_x = '+str(n_x)+', n_y = '+str(n_y)
        print 'raw = '+str(raw)
        return


    print 'building matrix'
    data = np.zeros((n_y,n_x))
    Zmat = np.zeros((n_y,n_x))

    for i in range(len(x)):
        i_y = yy.index(y[i])
        i_x = xx.index(x[i])
        #if raw['active species'][i]>5:
        if Z_cut is not None and Z[i]<Z_cut:
            data[i_y, i_x] = float('nan')
        else:
            data[i_y, i_x] = GPSA_data_list[i] * mutiplier
        Zmat[i_y, i_x] = Z[i]

    print 'plotting'


    colors = ['k','w']
    lw = [1,3]
    if len(Z_contour)>0:
        for i_v in range(len(Z_contour)):
            CS = plt.contour(Zmat, [Z_contour[0][i_v]], colors=colors[i_v], linewidths=lw[i_v])
            #plt.clabel(CS, fontsize=10, inline=1, fmt=Z_contour[1][i_v])
    #plt.legend(Z_contour[1])

    #imsave(key_show+'.png',data)
    if clim is None:
        plt.imshow(data, cmap=cmap)
    else:
        plt.imshow(data, clim=clim, cmap=cmap)

    plt.colorbar()

    #plt.show()
项目:pytorch-geometric-gan    作者:lim0606    | 项目源码 | 文件源码
def save_contour(netD, filename, cuda=False):
    #import warnings
    #warnings.filterwarnings("ignore", category=FutureWarning)
    #import numpy as np
    #import matplotlib
    #matplotlib.use('Agg')
    #import matplotlib.cm as cm
    #import matplotlib.mlab as mlab
    #import matplotlib.pyplot as plt

    matplotlib.rcParams['xtick.direction'] = 'out'
    matplotlib.rcParams['ytick.direction'] = 'out'
    matplotlib.rcParams['contour.negative_linestyle'] = 'solid' 

    # gen grid 
    delta = 0.1
    x = np.arange(-25.0, 25.0, delta)
    y = np.arange(-25.0, 25.0, delta)
    X, Y = np.meshgrid(x, y)

    # convert numpy array to to torch variable
    (h, w) = X.shape
    XY = np.concatenate((X.reshape((h*w, 1, 1, 1)), Y.reshape((h*w, 1, 1, 1))), axis=1)
    input = torch.Tensor(XY)
    input = Variable(input)
    if cuda:
        input = input.cuda()

    # forward
    output = netD(input)

    # convert torch variable to numpy array
    Z = output.data.cpu().view(-1).numpy().reshape(h, w)

    # plot and save 
    plt.figure()
    CS1 = plt.contourf(X, Y, Z)
    CS2 = plt.contour(X, Y, Z, alpha=.7, colors='k')
    plt.clabel(CS2, inline=1, fontsize=10, colors='k')
    plt.title('Simplest default with labels')
    plt.savefig(filename)
    plt.close()
项目:wrfplot    作者:liamtill    | 项目源码 | 文件源码
def mslponly(): # plot MSLP only
    #create figure
    plt.figure(figsize=(8,8))
    x, y = m(lons, lats)
    psfchpa = conv.pa_to_hpa(psfc[time]) #convert Pa to hPa     
    mslp = calc.calc_mslp(psfchpa, thgt[0], t2[time]) # get mslp
    mslp = gaussian_filter(mslp, sigma=3) #smooth wiggles
    #find local min and local max
    local_min, local_max = funcs.extrema(mslp, mode='wrap', window=50)       
    clevs = np.arange(900,1055,2.)        
    cs = m.contour(x,y,mslp,clevs,colors='k',linewidths=2.)
    plt.clabel(cs, inline=True, fmt='%1.0f', fontsize=12, colors='k')
    xlows = x[local_min];   xhighs = x[local_max]
    ylows = y[local_min];   yhighs = y[local_max]
    lowvals = mslp[local_min]; highvals = mslp[local_max]
    # plot lows as blue L's, with min pressure value underneath.
    xyplotted = []
    # don't plot if there is already a L or H within dmin meters.
    yoffset = 0.022*(m.ymax-m.ymin)
    dmin = yoffset
    for x,y,p in zip(xlows, ylows, lowvals):
        if x < m.xmax and x > m.xmin and y < m.ymax and y > m.ymin:
            dist = [np.sqrt((x-x0)**2+(y-y0)**2) for x0,y0 in xyplotted]
            if not dist or min(dist) > dmin:
                plt.text(x,y,'L',fontsize=14,fontweight='bold', ha='center',va='center',color='b')
                plt.text(x,y-yoffset,repr(int(p)),fontsize=12, ha='center',va='top',color='b', bbox = dict(boxstyle="square",ec='None',fc=(1,1,1,0.5)))
                xyplotted.append((x,y))
    # plot highs as red H's, with max pressure value underneath.
    xyplotted = []
    for x,y,p in zip(xhighs, yhighs, highvals):
        if x < m.xmax and x > m.xmin and y < m.ymax and y > m.ymin:
            dist = [np.sqrt((x-x0)**2+(y-y0)**2) for x0,y0 in xyplotted]
            if not dist or min(dist) > dmin:
                plt.text(x,y,'H',fontsize=14,fontweight='bold', ha='center',va='center',color='r')
                plt.text(x,y-yoffset,repr(int(p)),fontsize=12, ha='center',va='top',color='r', bbox = dict(boxstyle="square",ec='None',fc=(1,1,1,0.5)))
                xyplotted.append((x,y))
    title = "MSLP (hPa)"
    ftitle = 'mslp-'
    cblabel = ''
    clevs = False # no color bar levels
    cbticks = False
    makeplot(cs,title,cblabel,clevs,cbticks,ftitle)
项目:wrfplot    作者:liamtill    | 项目源码 | 文件源码
def upperair(): # plot upper air chart for given level. geopotential height, wind bards and temp
    pb = nc.variables['PB'][time] #base state pressure, Pa
    p = nc.variables['P'][time] # perturbation pressure, Pa
    totalp = pb + p # total pressure in Pa
    U = nc.variables['U'][time] # U wind component
    V = nc.variables['V'][time] # V wind component
    Unew = funcs.unstagger(U,'U') # unstagger u
    Vnew = funcs.unstagger(V,'V') # unstagger v
    ph = nc.variables['PH'][time] #perturbation geopotential
    phb = nc.variables['PHB'][time] #base state geopotential
    totalgp = phb + ph # total geopotential
    totalgp = funcs.unstagger(totalgp,'Z') #total geopotential unstaggered
    theta = nc.variables['T'][time] #perturbation potential temperature (theta-t0)
    theta0 = nc.variables['T00'][0] #base state theta
    totalTheta = theta + theta0 # total potential temp
    totalT = conv.k_to_c(calc.theta_to_temp(totalTheta, totalp)) # calc temps in C

    levels = opt.lvl.split(',') # get list of levels
    for level in levels: 
        plt.figure(figsize=(8,8)) #create fig for each plot
        level = int(level) # make it int
        #interp data for level
        gphgt = funcs.linear_interp(totalgp,totalp,level)
        totalTfinal = funcs.linear_interp(totalT,totalp,level)     
        uinterp = funcs.linear_interp(Unew,totalp,level)
        vinterp = funcs.linear_interp(Vnew,totalp,level) 
        Ufinal = conv.ms_to_kts(uinterp) #convert to kts
        Vfinal = conv.ms_to_kts(vinterp)
        #speed = calc.calc_wspeed(Ufinal, Vfinal)
        gphgt = conv.gphgt_to_hgt(gphgt) # convert to height (m)
        gphgt = gaussian_filter(gphgt, sigma=3) # smooth wiggles  
        totalTfinal = gaussian_filter(totalTfinal, sigma=2)
        # set gpheight levels for common pressure levels        
        if level == 250:
            gpclevs = np.arange(np.min(gphgt),np.max(gphgt),60)
        elif level == 500:
            gpclevs = np.arange(np.min(gphgt),np.max(gphgt),60)
        elif level == 700:
            gpclevs = np.arange(np.min(gphgt),np.max(gphgt),30)
        elif level == 850:
            gpclevs = np.arange(np.min(gphgt),np.max(gphgt),30)
        elif level == 925:
            gpclevs = np.arange(np.min(gphgt),np.max(gphgt),30)
        else: # use generic 30m spacing
            gpclevs = np.arange(np.min(gphgt),np.max(gphgt),30)

        #plot all this up    
        cs = m.contour(x,y,gphgt,gpclevs,colors='k',linewidths=2.)
        plt.clabel(cs, inline=True, fmt='%1.0f', fontsize=12, colors='k')
        tclevs = np.arange(np.min(totalTfinal),np.max(totalTfinal),4)
        cs2 = m.contour(x,y,totalTfinal,tclevs,colors='r',linestyles='-',linewidths=2.)
        plt.clabel(cs2,inline=True,fmt='%1.0f',fontsize=12,colors='r')
        m.barbs(x[::thin,::thin], y[::thin,::thin], Ufinal[::thin,::thin], Vfinal[::thin,::thin],length=opt.barbsize) #plot barbs
        level = str(level)
        title = level+'mb Height (m), Temp (C), Wind Barbs (kts)'
        ftitle = level+'mb-' 
        cblabel = 'kts'
        clevs = False
        cbticks = False
        makeplot(cs,title,cblabel,clevs,cbticks,ftitle)
项目:oceanobs    作者:rbardaji    | 项目源码 | 文件源码
def plot_ts(self, name_temp):
        """
        Graph of T-S.
        :param name_temp: Key of the *data* variable that contains the temperature values.
        :return: figure
        """
        try:
            temp = self.data[name_temp]
            salt = self.data['psal']
        except KeyError:
            return "Error: Not enough data."

        # Figure out boundaries (mins and maxs)
        smin = salt.min() - (0.01 * salt.min())
        smax = salt.max() + (0.01 * salt.max())
        tmin = temp.min() - (0.1 * temp.max())
        tmax = temp.max() + (0.1 * temp.max())

        # Calculate how many grid cells we need in the x and y dimensions
        xdim = round((smax - smin) / 0.1 + 1, 0)
        ydim = round((tmax - tmin) + 1, 0)

        # Create empty grid of zeros
        dens = np.zeros((np.int(ydim), np.int(xdim)))

        # Create temp and salt vectors of appropriate dimensions
        ti = np.linspace(1, ydim - 1, ydim) + tmin
        si = np.linspace(1, xdim - 1, xdim) * 0.1 + smin

        # Loop to fill in grid with densities
        for j in range(0, int(ydim)):
            for i in range(0, int(xdim)):
                dens[j, i] = gsw.rho(si[i], ti[j], 0)

        # Subtracts 1000 to convert to sigma-t
        dens -= 1000

        # Plot data ***********************************************
        fig_ts = plt.figure()
        ax1 = fig_ts.add_subplot(111)
        cs = plt.contour(si, ti, dens, linestyles='dashed', colors='k')
        plt.clabel(cs, fontsize=12, inline=1, fmt='%1.1f')  # Label every second level

        ax1.plot(salt, temp, 'or', markersize=9)

        ax1.set_xlabel('PSU')
        ax1.set_ylabel('ºC')
        ax1.set_title("T-S diagram")
        return fig_ts