本文整理汇总了Python中mpl_toolkits.basemap.Basemap.pcolor方法的典型用法代码示例。如果您正苦于以下问题:Python Basemap.pcolor方法的具体用法?Python Basemap.pcolor怎么用?Python Basemap.pcolor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mpl_toolkits.basemap.Basemap
的用法示例。
在下文中一共展示了Basemap.pcolor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plot_cedata
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import pcolor [as 别名]
def plot_cedata(lats, lons, data, title):
"""
Plot coefficient of efficiency data. Lats, lons, and data should have the
same temporal dimensions. Lats and lons should denote gridbox edges.
e.g. data has spatial dimensions of M (lats) x N (lons) then lats and lons
should have dimensions of M+1 x N+1.
Parameters
----------
lats: ndarray
Latitude array (gridbox edges)
lons: ndarray
Longitude array (gridbox edges)
data: ndarray
CE data
title: str
Plot title
"""
plt.close('all')
m = Basemap(projection='gall', llcrnrlat=-90, urcrnrlat=90,
llcrnrlon=0, urcrnrlon=360, resolution='c')
m.drawcoastlines()
if data.min() < 0:
color = cm.bwr
else:
color = cm.OrRd
m.pcolor(lons, lats, data, latlon=True, cmap=color, vmin=-1, vmax=1)
m.colorbar()
plt.title(title)
plt.show()
示例2: nsolLots
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import pcolor [as 别名]
def nsolLots():
''' Compare nSol estimates to insolation. '''
# Read the data first:
nsolTable = readNsol()
lons = [p['LonW'] for p in nsolTable]
lats = [p['LatN'] for p in nsolTable]
sizes = [p['ArrayOutput'] for p in nsolTable]
insolSizes = [p['TotalAnnualInsolation'] for p in nsolTable]
bmOptions = {'projection':'merc', 'lon_0':-95, 'lat_0':35, 'llcrnrlat':20, 'urcrnrlat':50,
'llcrnrlon':-130, 'urcrnrlon':-60, 'rsphere':6371200., 'resolution':'l', 'area_thresh':10000}
# First Plot
plt.subplot(211)
m1 = Basemap(**bmOptions)
m1.drawcoastlines()
m1.drawstates()
m1.drawcountries()
plt.title('Panel Output')
mesh1 = m1.pcolor(lons, lats, sizes, latlon=True, tri=True)
cbar1 = m1.colorbar(mesh1,location='right',pad='5%')
cbar1.set_label('kWh')
# Second Plot
plt.subplot(212)
m2 = Basemap(**bmOptions)
m2.drawcoastlines()
m2.drawstates()
m2.drawcountries()
plt.title('Annual Insolation')
mesh2 = m2.pcolor(lons, lats, insolSizes, latlon=True, tri=True)
cbar2 = m2.colorbar(mesh2,location='right',pad='5%')
cbar2.set_label('kWh/m^2')
示例3: plot_anomaly_ll
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import pcolor [as 别名]
def plot_anomaly_ll(lat, lon, var):
#Input lat and lon in degrees!!!
plt.figure()
#m = Basemap(projection='ortho',lon_0=100,lat_0=60, resolution='l')
m = Basemap(projection='ortho',lon_0=0,lat_0=90, resolution='l')
x,y = m(lon, lat)
m.drawcoastlines()
m.drawmapboundary()
#'''
#set bounds on var
maxVal = 100.; minVal = -100.
var[var>maxVal] = maxVal
var[var<minVal] = minVal
#'''
m.pcolor(x,y,var,shading='flat',edgecolors='none',cmap=plt.cm.jet) #cmap=plt.cm.hot_r) #,vmin=100,vmax=1000)
#m.contour(x,y,var,10,tri=True,shading='flat',edgecolors='none',cmap=plt.cm.jet)
#m.contourf(x,y,var,10,tri=True,shading='flat',edgecolors='none',cmap=plt.cm.jet)
#cbar = m.colorbar(plt1,location='bottom',pad="5%")
#cbar.set_label('\Delta m')
plt.colorbar()
plt.show()
示例4: plot_region_pnw
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import pcolor [as 别名]
def plot_region_pnw(data,lat_coord,lon_coord,lat_nw,lat_se,lon_nw,lon_se,title,varfrac):
plt.clf()
circles=[30,40,50,60,70]
meridians=[-130,-120,-110]
ny,nx=lat_coord.shape
m = Basemap(projection='stere',lon_0=lon_coord[ny/2,nx/2],lat_0=lat_coord[ny/2,nx/2],resolution='l',llcrnrlon=lon_coord[-1,0],llcrnrlat=lat_coord[-1,0],urcrnrlon=lon_coord[0,-1],urcrnrlat=lat_coord[0,-1])
x,y=m(lon_coord[:],lat_coord[:])
plt.title('Plotting data for: '+title+'\nvariance:'+str(varfrac))
try:
max=np.absolute(data[lat_nw:lat_se,lon_nw:lon_se]).max()
m.pcolor(x[lat_nw:lat_se,lon_nw:lon_se],y[lat_nw:lat_se,lon_nw:lon_se],data[lat_nw:lat_se,lon_nw:lon_se],vmin=-max,vmax=max)
plt.colorbar()
except:
raise
m.plot(x[lat_nw:lat_se,lon_nw:lon_se],y[lat_nw:lat_se,lon_nw:lon_se],'r.') # Just put a dot at the x y point
m.drawcoastlines()
m.drawcountries()
y=m.drawstates()
m.drawparallels(circles)
m.drawmeridians(meridians)
try:
os.remove(output_dir+'/._'+title+'.png')
except:
pass
plt.savefig(output_dir+'/'+title+'.png')
示例5: plot_region_pnw
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import pcolor [as 别名]
def plot_region_pnw(data,lat_coord,lon_coord,lat_nw,lat_se,lon_nw,lon_se,region_name):
plt.clf()
circles=[30,40,50,60,70]
meridians=[-130,-120,-110]
ny,nx=lat_coord.shape
m = Basemap(projection='stere',lon_0=lon_coord[ny/2,nx/2],lat_0=lat_coord[ny/2,nx/2],resolution='l',llcrnrlon=lon_coord[-1,0],llcrnrlat=lat_coord[-1,0],urcrnrlon=lon_coord[0,-1],urcrnrlat=lat_coord[0,-1])
x,y=m(lon_coord[:],lat_coord[:])
# shp_info = m.readshapefile('../st99_d00','states',drawbounds=False)
# print shp_info
# for i,shapedict in enumerate(m.states_info):
# if shapedict['NAME']=='California': break
# calif=np.array(m.states[i])
# TODO rasterise this to turn into a mask
plt.title('Plotting data for region: '+region_name)
try:
m.pcolor(x[lat_nw:lat_se,lon_nw:lon_se],y[lat_nw:lat_se,lon_nw:lon_se],data[lat_nw:lat_se,lon_nw:lon_se])
plt.colorbar()
except:
raise
m.plot(x[lat_nw:lat_se,lon_nw:lon_se],y[lat_nw:lat_se,lon_nw:lon_se],'r.') # Just put a dot at the x y point
m.drawcoastlines()
m.drawcountries()
y=m.drawstates()
m.drawparallels(circles)
m.drawmeridians(meridians)
try:
os.remove('check_regions/._'+region_name+'.png')
except:
pass
plt.savefig('check_regions/'+region_name+'.png')
示例6: plot_mask
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import pcolor [as 别名]
def plot_mask(gridid, Cpos='rho', proj=None, **kwargs):
# get grid
if type(gridid).__name__ == 'ROMS_Grid':
grd = gridid
else:
grd = pyroms.grid.get_ROMS_grid(gridid)
Cpos = str(Cpos)
print Cpos
# get grid information
if Cpos == 'rho':
lon = grd.hgrid.lon_vert
lat = grd.hgrid.lat_vert
mask = grd.hgrid.mask_rho
elif Cpos == 'u':
lon = 0.5 * (grd.hgrid.lon_vert[:,:-1] + grd.hgrid.lon_vert[:,1:])
lat = 0.5 * (grd.hgrid.lat_vert[:,:-1] + grd.hgrid.lat_vert[:,1:])
mask = grd.hgrid.mask_u
elif Cpos == 'v':
lon = 0.5 * (grd.hgrid.lon_vert[:-1,:] + grd.hgrid.lon_vert[1:,:])
lat = 0.5 * (grd.hgrid.lat_vert[:-1,:] + grd.hgrid.lat_vert[1:,:])
mask = grd.hgrid.mask_v
else:
raise Warning, 'Cpos must be rho, u or v'
# defined color map
land_color = kwargs.pop('land_color', (0.6, 1.0, 0.6))
sea_color = kwargs.pop('sea_color', (0.6, 0.6, 1.0))
cm = plt.matplotlib.colors.ListedColormap([land_color, sea_color],
name='land/sea')
if proj is None:
plt.pcolor(lon, lat, mask, cmap=cm, vmin=0, vmax=1, \
edgecolor='k', **kwargs)
pyroms_toolbox.plot_coast_line(grd)
else:
x, y = proj(lon, lat)
Basemap.pcolor(proj, x, y, mask, cmap=cm, vmin=0, vmax=1, \
edgecolor='k', **kwargs)
pyroms_toolbox.plot_coast_line(grd, proj=proj)
lon_min = lon.min()
lon_max = lon.max()
lat_min = lat.min()
lat_max = lat.max()
proj.drawmeridians(np.arange(lon_min,lon_max,(lon_max-lon_min)/5.001), \
labels=[0,0,0,1], fmt='%.1f')
proj.drawparallels(np.arange(lat_min,lat_max,(lat_max-lat_min)/5.001), \
labels=[1,0,0,0], fmt='%.1f')
示例7: generate_image
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import pcolor [as 别名]
def generate_image(year, month, xs=500, ys=500, elev=60, azim=-90, colormap=cm.seismic):
m = Basemap(width=12000000,height=12000000,
rsphere=(6378137.00,6356752.3142),\
resolution='l',area_thresh=1000.,projection='lcc',\
lat_0=45,lon_0=170)
ssl_loc = '/home/guy/Data/cci-ssl/ESACCI-SEALEVEL-L4-MSLA-MERGED-%04d%02d15000000-fv01.nc' % (year, month)
lons_proj, lats_proj, XX, YY, sla = reproject_data(ssl_loc,'sla', m, xsize=xs, ysize=ys, filter=0)
sst_loc = '/mnt/surft/data/SST_CCI_L4_monthly_mean_anomalies/%04d%02d--ESACCI-L4_GHRSST-SSTdepth-OSTIA-GLOB_LT-v02.0-fv01.0_anomalies.nc' %(year, month)
lons_proj, lats_proj, XX, YY, sst = reproject_data(sst_loc,'sst_anomaly', m, xsize=xs, ysize=ys, filter=None)
min_sst = -4
max_sst = 4
colors = np.empty(sst.shape, dtype=np.dtype((float, (4))))
for y in range(sst.shape[1]):
for x in range(sst.shape[0]):
val = sst[x, y]
if(np.ma.getmask(sst[x,y]) == True):
colors[x,y] = (1,0,0,0)
else:
zero_to_one = (val - min_sst) / (max_sst - min_sst)
colors[x, y] = colormap(zero_to_one)
fig = plt.figure(figsize=(19.2,9.6))
ax = plt.subplot(121, projection='3d')
# ax = fig.gca(projection='3d')
ax.view_init(elev=elev, azim=azim)
ax.set_axis_off()
surf = ax.plot_surface(XX, YY, sla, rstride=1, cstride=1, facecolors=colors,#cmap=cm.coolwarm,
linewidth=0, antialiased=False)
ax.set_zlim(-3, 3)
ax.set_xlim((0.22 * xs, 0.78 * xs))
ax.set_ylim((0.18 * ys, 0.82 * ys))
ax2d = plt.subplot(122, aspect=1)
m.bluemarble(ax=ax2d, scale=0.2)
#m.imshow(sst, ax=ax, cmap=cm.coolwarm)
x, y = m(lons_proj, lats_proj)
m.pcolor(x,y, sst, ax=ax2d, cmap=colormap, vmin=min_sst, vmax=max_sst)
#matplotlib.rcParams['contour.negative_linestyle'] = 'dashed'
m.contour(x,y, sla, np.linspace(-1,1,11), colors='k', ax=ax2d)
# m.pcolor(XX, YY, sla, ax=ax)
#ax.pcolormesh(XX,YY,sst, vmin=min_sst, vmax=max_sst, cmap=cm.coolwarm)
# ax = fig.gca()
# surf = ax.pcolormesh(XX,YY,sla, vmin=-limit, vmax=limit)
# fig.colorbar(surf, shrink=0.5, aspect=5)
fig.tight_layout()
return fig
示例8: plot_2dll
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import pcolor [as 别名]
def plot_2dll(lat, lon, var):
#map = Basemap(projection='ortho',lon_0=100,lat_0=60, resolution='l')
map = Basemap(projection='ortho',lon_0=0,lat_0=90, resolution='l')
x,y = map(lon, lat)
fig1 = plt.figure(1)
map.drawcoastlines()
map.drawmapboundary()
map.pcolor(x,y,var,shading='flat',edgecolors='none',cmap=plt.cm.jet) #cmap=plt.cm.hot_r) #,vmin=100,vmax=1000)
#map.contour(x,y,var,10,tri=True,shading='flat',edgecolors='none',cmap=plt.cm.jet)
#map.contourf(x,y,var,10,tri=True,shading='flat',edgecolors='none',cmap=plt.cm.jet)
plt.colorbar()
plt.show()
示例9: bp
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import pcolor [as 别名]
def bp(lon, lat, data, yescbar, region = 'Arctic', ptype = 'contourf', **kwargs):
'''Basic Basemap plot function. Use coordinates (1d or 2d), data and name of the region
as an input and plot data. Region defines in the "regbase" function.
You can also provide any argument for matplotlib plotting functions.
Usage:
bp(lon, lat, data, region = 'Arctic', ptype = 'contourf', **kwargs)
Input:
lon - 2D or 1D array of longitudes
lat - 2D or 1D array of latitudes
data - 2D array of scalar data.
region - one of the predefined regions (for list of regions see the "regbase" function)
ptype - plot type (contour, contourf, pcolor, pcolormesh)
**kwargs - arguments for plotting functions
Output:
Basemap instance.
'''
mapDict = regbase(region)
# Create Basemap instance
if mapDict['projection'] == 'npstere':
m = Basemap(projection=mapDict['projection'],boundinglat=mapDict['boundinglat'],\
lon_0=mapDict['lon_0'],resolution=mapDict['resolution'])
# Check if we have proper number of dimensions for lon (and hopefully lat as well)
if lon.shape.__len__() == 1:
lon, lat = np.meshgrid(lon, lat)
elif lon.shape.__len__() > 2:
raise Exception("Coordinate variables (lon) has too many dimensions")
# Convert lat/lon to map coordinates
x, y = m(lon, lat)
# Make the map look better
m.fillcontinents(color='gray',lake_color='gray')
m.drawparallels(np.arange(-80.,81.,20.))
m.drawmeridians(np.arange(-180.,181.,20.))
m.drawmapboundary(fill_color='white')
# Draw values on the map
if ptype == 'contourf':
cs = m.contourf(x,y,data,**kwargs)
if yescbar == True:
cbar3 = plt.colorbar(cs)
return m
elif ptype == 'pcolormesh':
cs = m.pcolormesh(x,y,data,**kwargs)
elif ptype == 'contour':
cs = m.contour(x,y,data,**kwargs)
elif ptype == 'pcolor':
cs = m.pcolor(x,y,data,**kwargs)
else:
raise Exception("Plot type not supported. Valid plot types are: contour, contourf, pcolor, pcolormesh ")
return m
示例10: hammer_plot_density
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import pcolor [as 别名]
def hammer_plot_density(density, xmax, xmin, ymax, ymin, no_ra, no_dec, targ_flag, obs_flag, pass_flag):
if targ_flag ==1:
targ_type = 'LRG'
if targ_flag==2:
targ_type = 'ELG'
if targ_flag==4:
targ_type = 'QSO'
if obs_flag==1:
name_obs = 'source'
if obs_flag==2:
name_obs = 'true'
outfile = "~/DESIhub/target_density_%s_%s_pass%d.pdf" %(targ_type, name_obs, pass_flag)
bin_size_x = (xmax-xmin)/no_ra
bin_size_y = (ymax-ymin)/no_dec
y = np.linspace(ymin, ymax, no_dec)
x = np.linspace(xmin, xmax, no_ra)
[X,Y] = np.meshgrid(x,y);
X=np.transpose(X)
Y=np.transpose(Y)
f = plt.figure()
m = Basemap(projection='moll',lon_0=180,resolution='c')
cs = m.pcolor(X, Y, density, cmap=plt.cm.jet,latlon=True)
cbar = m.colorbar(cs,location='bottom',pad="5%")
f.savefig(outfile, bbox_inches='tight')
示例11: plot_satellite_image
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import pcolor [as 别名]
def plot_satellite_image(filename):
"""takes in a file and outputs a plot of satellite"""
rootgrp = Dataset(filename, "a", format="NETCDF4")
lons = rootgrp.variables["lon"][:]
lats = rootgrp.variables["lat"][:]
data = rootgrp.variables["data"][:]
rootgrp.close() # need to close before you can open again
# Get some parameters for the Stereographic Projection
m = Basemap(
width=800000,
height=800000, # create a basemap object with these parameters
resolution="l",
projection="stere",
lat_ts=40,
lat_0=39.5,
lon_0=-104.5,
)
xi, yi = m(lons, lats) # map onton x and y for plotting
plt.figure(figsize=(10, 10)) # Plot Data
cs = m.pcolor(xi, yi, np.squeeze(data)) # data is 1 x 14 x 36, squeeze makes it 14 x 36
m.drawparallels(np.arange(-80.0, 81.0, 1.0), labels=[1, 0, 0, 0], fontsize=10) # Add Grid Lines
m.drawmeridians(np.arange(-180.0, 181.0, 1.0), labels=[0, 0, 0, 1], fontsize=10) # Add Grid Lines
m.drawstates(linewidth=3) # Add state boundaries
cbar = m.colorbar(cs, location="bottom", pad="10%") # Add Colorbar
plt.title("GOES 15 - Sensor 1") # Add Title
plt.show()
示例12: worldmap_velocitymap
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import pcolor [as 别名]
def worldmap_velocitymap(params,plotName):
"""@worldmap plot
@param params
seismon params dictionary
@param plotName
name of plot
"""
plt.figure(figsize=(15,10))
plt.axes([0,0,1,1])
# lon_0 is central longitude of robinson projection.
# resolution = 'c' means use crude resolution coastlines.
m = Basemap(projection='robin',lon_0=0,resolution='c')
#set a background colour
m.drawmapboundary(fill_color='#85A6D9')
# draw coastlines, country boundaries, fill continents.
m.fillcontinents(color='white',lake_color='#85A6D9')
m.drawcoastlines(color='#6D5F47', linewidth=.4)
m.drawcountries(color='#6D5F47', linewidth=.4)
# draw lat/lon grid lines every 30 degrees.
m.drawmeridians(np.arange(-180, 180, 30), color='#bbbbbb',zorder=3)
m.drawparallels(np.arange(-90, 90, 30), color='#bbbbbb',zorder=3)
velocityFile = '/home/mcoughlin/Seismon/velocity_maps/GR025_1_GDM52.pix'
velocity_map = np.loadtxt(velocityFile)
base_velocity = 3.59738
lats = velocity_map[:,0]
lons = velocity_map[:,1]
velocity = 1000 * (1 + 0.01*velocity_map[:,3])*base_velocity
lats_unique = np.unique(lats)
lons_unique = np.unique(lons)
velocity_matrix = np.zeros((len(lats_unique),len(lons_unique)))
for k in xrange(len(lats)):
index1 = np.where(lats[k] == lats_unique)
index2 = np.where(lons[k] == lons_unique)
velocity_matrix[index1[0],index2[0]] = velocity[k]
lons_grid,lats_grid = np.meshgrid(lons_unique,lats_unique)
x, y = m(lons_grid, lats_grid) # compute map proj coordinates.
# draw filled contours.
cs = m.pcolor(x,y,velocity_matrix,alpha=0.5,zorder=2)
colorbar_label = "Velocity [m/s]"
try:
cbar=plt.colorbar()
cbar.set_label(colorbar_label)
except:
pass
plt.show()
plt.savefig(plotName,dpi=200)
plt.close('all')
示例13: example_sfcUpdate_horiz
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import pcolor [as 别名]
def example_sfcUpdate_horiz(time,var):
#The surfaceUpdate.nc files don't have all of the same fields/dimensions,...
#so we get errors when attempting to access them
import netCDF4
ncfname = '/arctic1/nick/cases/163842/r2614/sfc_update.nc'
ncfnameG = '/arctic1/nick/cases/163842/r2614/output.163842.2006-07-08_00.00.00.nc' #used for grid since, say, sfc_update.nc doesn't have this info
dataG = netCDF4.Dataset(ncfnameG,'r')
data = netCDF4.Dataset(ncfname,'r')
nCells = len(data.dimensions['nCells'])
lat = dataG.variables['latCell'][:]*180./np.pi; #in degrees
lon = dataG.variables['lonCell'][:]*180./np.pi;
level = 0; #time=20; var='sst';
var = data.variables[var][time,:];# minVar = np.amin(var); maxVar = np.amax(var);
#map = Basemap(projection='ortho',lon_0=-105,lat_0=40, resolution='l')
map = Basemap(projection='ortho',lon_0=-100,lat_0=60, resolution='l')
x,y = map(lon, lat)
fig1 = plt.figure(1)
map.drawcoastlines()
map.drawmapboundary()
map.pcolor(x,y,var,tri=True,shading='flat',edgecolors='none',cmap=plt.cm.jet) #cmap=plt.cm.hot_r) #,vmin=100,vmax=1000)
#map.contour(x,y,var,10,tri=True,shading='flat',edgecolors='none',cmap=plt.cm.jet)
#map.contourf(x,y,var,10,tri=True,shading='flat',edgecolors='none',cmap=plt.cm.jet)
plt.colorbar()
if(1):
map = Basemap(projection='ortho',lon_0=100,lat_0=-60, resolution='l')
x,y = map(lon, lat)
fig2 = plt.figure(2)
map.drawcoastlines()
map.drawmapboundary()
map.pcolor(x,y,var,tri=True,shading='flat',edgecolors='none',cmap=plt.cm.jet) #cmap=plt.cm.hot_r) #,vmin=100,vmax=1000)
#map.contour(x,y,var,10,tri=True,shading='flat',edgecolors='none',cmap=plt.cm.jet)
#map.contourf(x,y,var,10,tri=True,shading='flat',edgecolors='none',cmap=plt.cm.jet)
plt.colorbar()
#plotName = '/home/nickszap/Desktop/sst'+str(time)+'.png'
#fig1.savefig(plotName)
plt.show()
示例14: plot_hrrr_sgp
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import pcolor [as 别名]
def plot_hrrr_sgp(filename,parameter,directory = os.getcwd(),hinp = '', scaling = 1, final_unit = '', margin = 10, vmax = None, vmin = None):
"""
Plots an hrrr file focused on the SGP site for a given hrrr filename, parameter and height in hPa.
Labels the SGP site.
Leaving the height blank will cause it to plot the maximum values of the file. The margin defines half the length of
the plot area in degrees latitude and longitude. Scaling and final_unit can be used to tweak the data in order to
make it more visible on the graph. vmax and vmin function the same as in pcolormesh from Basemap.
"""
wkdir = os.getcwd()
os.chdir(directory)
if hinp != '':
[data,parameterlist,units] = read_hrrr(filename,[parameter])
else:
[data,parameterlist,units] = read_hrrr(filename,[parameter],directory = directory,max=True)
if hinp !='':
datah = HRRR_PS.tolist()
hindex = datah.index(hinp)
if final_unit == '':
final_unit = units[0]
f = plt.figure(figsize=[12,10])
m = Basemap(llcrnrlon = -97.485-margin,llcrnrlat = 36.605-margin, urcrnrlon = -97.485+margin,
urcrnrlat = 36.605+margin, projection = 'mill', area_thresh =10000 ,
resolution='l')
latlonsgp = [-97.485,36.605]
cities = ['Lamont,OK']
sgpx,sgpy = m(latlonsgp[0],latlonsgp[1])
m.plot(sgpx,sgpy,'bo')
#plt.text(sgpx+50000,sgpy+50000,'SGP site')
x, y = m(HRRR_DATALOC[1],HRRR_DATALOC[0])
data = np.array(data)
if hinp != '':
newdata = data[0][hindex][:][:]
else:
newdata = data[0]
my_mesh = m.pcolor(x, y, newdata, vmax = .05, norm = colors.LogNorm())
# my_coast = m.drawcoastlines(linewidth=1.25)
# my_states = m.drawstates()
# my_p = m.drawparallels(np.arange(20,80,4),labels=[1,1,0,0])
# my_m = m.drawmeridians(np.arange(-140,-60,4),labels=[0,0,0,1])
plt.colorbar(label=parameter+' '+final_unit)
plt.show()
os.chdir(wkdir)
return
示例15: plot_nc
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import pcolor [as 别名]
def plot_nc(lons, lats, precips):
m = Basemap(width=200000, height=200000, projection='stere',
lat_0=lat_0, lon_0=lon_0)
lon, lat = np.meshgrid(lons, lats)
xi, yi = m(lon, lat)
cs = m.pcolor(xi, yi, precips[0])
m.drawstates()
m.drawcounties()
cbar = m.colorbar(cs, location='bottom', pad='10%')
plt.show()