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


Python Basemap.streamplot方法代码示例

本文整理汇总了Python中mpl_toolkits.basemap.Basemap.streamplot方法的典型用法代码示例。如果您正苦于以下问题:Python Basemap.streamplot方法的具体用法?Python Basemap.streamplot怎么用?Python Basemap.streamplot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mpl_toolkits.basemap.Basemap的用法示例。


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

示例1: plot_topBL

# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import streamplot [as 别名]
    def plot_topBL(self,datagrid,ugrid,vgrid,filename):
      
        module = (np.sqrt(ugrid*ugrid+vgrid*vgrid))*3.6
        
        fig = plt.figure(figsize=(figsize,figsize),dpi=self.cfg.map_dpi)
        
        Lon,Lat = np.meshgrid(self.lon, self.lat)
        
        map = Basemap(llcrnrlon=self.BB['lon'][0],llcrnrlat=self.BB['lat'][0],urcrnrlon=self.BB['lon'][1],urcrnrlat=self.BB['lat'][1],
                      rsphere=(6378137.00,6356752.3142), resolution='l',projection='merc')
    
        x, y = map(Lon, Lat)
        cs2 = map.contourf(x,y,datagrid,512)
        
        levels = np.arange(0, 5000, 100)
        CS = map.contour(x,y,datagrid, levels, linewidths=0.01,colors = 'k')
        plt.clabel(CS,inline=1,fmt='%d')

        lw = 1 + 4*module/50
        map.streamplot(x,y,ugrid,vgrid, density=3, color='k', linewidth=lw , arrowsize=2 )

        for ix in np.arange(0,module.shape[1],2):
            for iy in np.arange(0,module.shape[0],2):
                #print ix,iy
                ilon = self.lon[ix]
                ilat = self.lat[iy]      
                a,b = map(ilon,  ilat)
                plt.text(a,b  ,int(module[iy,ix]),fontsize=fontsize,fontweight='bold', ha='center',va='center',color='r')

        plt.subplots_adjust(left=0.0, right=figsize, top=figsize, bottom=0.0)
        
        self.saveplot(plt,filename)
        plt.close()
        
        
        # Legend
        fig1 = plt.figure(figsize=(11,11),dpi=100)
        cb = map.colorbar(cs2,"bottom", size="5%", pad="100%")
        
        
        name = filename + '_legend.jpg' 
        plt.savefig("maps/"+name, dpi=100,bbox_inches='tight',transparent=False)
        plt.close()
        list_of_maps_to_send.append("maps/"+name)

        
        img1 = Image.open("maps/"+name)
        w, h = img1.size
        box = (20, h-70, w-10, h-10)
        area = img1.crop(box)
        area.save("maps/"+name, 'jpeg')
        plt.close()
开发者ID:ToninoTarsi,项目名称:OpenMeteoData-PI,代码行数:54,代码来源:omdpi.py

示例2: plot2D_field

# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import streamplot [as 别名]
    def plot2D_field(self,gridu,gridv,module,direction,filename):
      
        fig = plt.figure(figsize=(figsize,figsize),dpi=self.cfg.map_dpi)
        
        Lon,Lat = np.meshgrid(self.lon, self.lat)
        
        map = Basemap(llcrnrlon=self.BB['lon'][0],llcrnrlat=self.BB['lat'][0],urcrnrlon=self.BB['lon'][1],urcrnrlat=self.BB['lat'][1],
                      rsphere=(6378137.00,6356752.3142), resolution='l',projection='merc')
    
        
        x, y = map(Lon, Lat)
        cs2 = map.contourf(x,y,module,512)
        
#        barbs = map.barbs(x,y,gridu,gridv,length=8,barbcolor='k',flagcolor='r',linewidth=0.5)
#         barbs = map.quiver(x,y,gridu,gridv,scale=100)
#         qk = plt.quiverkey(barbs, 0.1, 0.1, 20, '20 m/s', labelpos='W')

        lw =  lw = 1 + 4*module/module.max()
        map.streamplot(x,y,gridu,gridv, density=3, color='k', linewidth=lw , arrowsize=2 )

        plt.subplots_adjust(left=0.0, right=figsize, top=figsize, bottom=0.0)
        
        self.saveplot(plt,filename)
        plt.close()

        
        fig1 = plt.figure(figsize=(11,11),dpi=100)
        cb = map.colorbar(cs2,"bottom", size="5%", pad="100%")
        
        name = filename + '_legend.jpg' 
        plt.savefig("maps/"+name, dpi=100,bbox_inches='tight',transparent=False)
        plt.close()
        list_of_maps_to_send.append("maps/"+name)

        
        img1 = Image.open("maps/"+name)
        w, h = img1.size
        box = (20, h-70, w-10, h-10)
        area = img1.crop(box)
        area.save("maps/"+name, 'jpeg')
        plt.close()
开发者ID:ToninoTarsi,项目名称:OpenMeteoData-PI,代码行数:43,代码来源:omdpi.py

示例3: NetCDFFile

# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import streamplot [as 别名]
ncfile = NetCDFFile('rita.nc')
udat = ncfile.variables['sfc_u'][0,:,:]
vdat = ncfile.variables['sfc_v'][0,:,:]
lons1 = ncfile.variables['longitude'][:]
lats1 = ncfile.variables['latitude'][:]
lat0 = lats1[len(lats1)/2]; lon0 = lons1[len(lons1)/2]
lons, lats = np.meshgrid(lons1,lats1)
ncfile.close()

# downsample to finer grid for nicer looking plot.
nlats = 2*udat.shape[0]; nlons = 2*udat.shape[1]
lons = np.linspace(lons1[0],lons1[-1],nlons)
lats = np.linspace(lats1[0],lats1[-1],nlats)
lons, lats = np.meshgrid(lons, lats)
udat = interp(udat,lons1,lats1,lons,lats)
vdat = interp(vdat,lons1,lats1,lons,lats)
speed = np.sqrt(udat**2+vdat**2)


fig = plt.figure(figsize=(8,8))
m = Basemap(projection='cyl',llcrnrlat=lats1[0],llcrnrlon=lons1[0],urcrnrlat=lats1[-1],urcrnrlon=lons1[-1],resolution='i')
x, y = m(lons,lats)
m.streamplot(x,y,udat,vdat,color=speed,linewidth=2,density=2,cmap=plt.cm.spectral)
m.colorbar()
m.drawcoastlines()
m.drawmeridians(np.arange(-120,-60,2),labels=[0,0,0,1])
m.drawparallels(np.arange(0,30,2),labels=[1,0,0,0])
plt.title('Hurricane Rita flow field visualized with streamlines',\
        fontsize=13)
plt.show()
开发者ID:AvlWx2014,项目名称:basemap,代码行数:32,代码来源:streamplot_demo.py

示例4: plot_flow_vectors_basemap

# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import streamplot [as 别名]
def plot_flow_vectors_basemap(lons, lats, uu, vv, flow_speed, subregion:list=None, grid_shape=None, ax:Axes=None,
                              streamplot=False, draw_colorbar=True):
    from mpl_toolkits.basemap import Basemap

    if grid_shape is None:
        grid_shape = (300, 300)

    if subregion is None:
        subregion = [0, 1, 0, 1]

    if ax is None:
        fig = plt.figure()



    nx, ny = lons.shape





    b = Basemap(lon_0=180,
                llcrnrlon=lons[35, 35],
                llcrnrlat=lats[35, 35],
                urcrnrlon=lons[nx // 2, ny // 2],
                urcrnrlat=lats[nx // 2, ny // 2],
                resolution="i", area_thresh=2000)

    # im = b.pcolormesh(xx, yy, flow_speed)
    # b.colorbar(im)
    stride = 6



    uu1, vv1 = b.rotate_vector(uu, vv, lons, lats)

    lons_g, lats_g, xx_g, yy_g = b.makegrid(*grid_shape, returnxy=True)

    nx, ny = lons_g.shape
    i_start, i_end = int(nx * subregion[0]), int(nx * subregion[1])
    j_start, j_end = int(ny * subregion[2]), int(ny * subregion[3])



    xt, yt, zt = lat_lon.lon_lat_to_cartesian(lons_g.flatten(), lats_g.flatten())
    xs, ys, zs = lat_lon.lon_lat_to_cartesian(lons.flatten(), lats.flatten())
    ktree = KDTree(data=list(zip(xs, ys, zs)))

    dists, inds = ktree.query(list(zip(xt, yt, zt)))

    uu_to_plot = uu1.flatten()[inds].reshape(lons_g.shape)
    vv_to_plot = vv1.flatten()[inds].reshape(lons_g.shape)
    flow_speed_to_plot = flow_speed.flatten()[inds].reshape(lons_g.shape)



    clevs = [0, 0.01, 0.02, 0.04, 0.06, 0.08, 0.12, 0.16]
    ncolors = len(clevs) - 1
    norm = BoundaryNorm(clevs, ncolors)
    cmap = cm.get_cmap("gist_ncar_r", ncolors)

    im = b.pcolormesh(xx_g, yy_g, flow_speed_to_plot, alpha=0.5, cmap=cmap, norm=norm)
    if not streamplot:

        b.quiver(xx_g[i_start:i_end:stride, j_start:j_end:stride], yy_g[i_start:i_end:stride, j_start:j_end:stride],
                      uu_to_plot[i_start:i_end:stride, j_start:j_end:stride], vv_to_plot[i_start:i_end:stride, j_start:j_end:stride],
                      headlength=2, headaxislength=2, headwidth=4, units="inches", color="k")



    else:
        b.streamplot(xx_g, yy_g, uu_to_plot, vv_to_plot, linewidth=0.4, density=3, arrowstyle="fancy", arrowsize=0.4, ax=ax, color="k")


    # im = b.contourf(xx_g, yy_g, flow_speed_to_plot, levels=clevs, alpha=0.5, cmap=cmap, norm=norm)


    cb = b.colorbar(im, location="bottom")
    cb.ax.set_visible(draw_colorbar)


    b.drawcoastlines(linewidth=0.3, ax=ax)

    if ax is None:
        fig.savefig("nemo/circ_annual_mean_basemap.png", bbox_inches="tight", dpi=300)
        plt.close(fig)

    return im
开发者ID:guziy,项目名称:RPN,代码行数:90,代码来源:plot_mean_circulation.py

示例5: Basemap

# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import streamplot [as 别名]
import matplotlib.pyplot as plt
from osgeo import gdal
import numpy


map = Basemap(
    llcrnrlon=-93.7,
    llcrnrlat=28.0,
    urcrnrlon=-66.1,
    urcrnrlat=39.5,
    projection="lcc",
    lat_1=30.0,
    lat_2=60.0,
    lat_0=34.83158,
    lon_0=-98.0,
)

ds = gdal.Open("../sample_files/wrf.tiff")
lons = ds.GetRasterBand(4).ReadAsArray()
lats = ds.GetRasterBand(5).ReadAsArray()
u10 = ds.GetRasterBand(1).ReadAsArray()
v10 = ds.GetRasterBand(2).ReadAsArray()
speed = numpy.sqrt(u10 * u10 + v10 * v10)
xx, yy = map.makegrid(v10.shape[1], v10.shape[0], returnxy=True)[2:4]

map.streamplot(xx, yy, u10, v10, color=speed, cmap=plt.cm.autumn, linewidth=0.5 * speed)

map.drawcoastlines(color="0.15")

plt.show()
开发者ID:paulvija,项目名称:BasemapTutorial,代码行数:32,代码来源:streamplot.py

示例6: Basemap

# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import streamplot [as 别名]
from mpl_toolkits.basemap import Basemap
import numpy as np
import matplotlib.pyplot as plt
m = Basemap(projection='cyl',resolution='i',  llcrnrlat=44.30,urcrnrlat=60.5,\
            llcrnrlon=4.750,urcrnrlon=18.00)
m.drawcoastlines()
#m.fillcontinents(color='coral',lake_color='aqua')
# draw parallels and meridians.
m.drawparallels(np.arange(-90.,91.,5), labels=[True, True, True, False])
m.drawmeridians(np.arange(-180.,181.,5), labels=[True, False, True, True])
#m.drawmapboundary(fill_color='aqua') 
x = np.linspace(5, 18, 10)
y=np.linspace(45, 60, 10)
X,Y = np.meshgrid(x, y)
U, V = 12*(X-11), 12*(Y-52)
#Default parameters, uniform grid
m.streamplot(X, Y, U, V)
#plt.show()
plt.savefig('/home/s.von.hall/seminar/bspstream.png')
开发者ID:simvh,项目名称:smi,代码行数:21,代码来源:bspstream.py


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