本文整理汇总了Python中matplotlib.toolkits.basemap.Basemap.contourf方法的典型用法代码示例。如果您正苦于以下问题:Python Basemap.contourf方法的具体用法?Python Basemap.contourf怎么用?Python Basemap.contourf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.toolkits.basemap.Basemap
的用法示例。
在下文中一共展示了Basemap.contourf方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Basemap
# 需要导入模块: from matplotlib.toolkits.basemap import Basemap [as 别名]
# 或者: from matplotlib.toolkits.basemap.Basemap import contourf [as 别名]
# Example to show how to make multi-panel plots.
# 2-panel plot, oriented vertically, colorbar on bottom.
rcParams["figure.subplot.hspace"] = 0.4 # more height between subplots
rcParams["figure.subplot.wspace"] = 0.5 # more width between subplots
# create new figure
fig = P.figure()
# panel 1
mnh = Basemap(lon_0=-105, boundinglat=20.0, resolution="c", area_thresh=10000.0, projection="nplaea")
xnh, ynh = mnh(lons, lats)
ax = fig.add_subplot(211)
CS = mnh.contour(xnh, ynh, hgt, 15, linewidths=0.5, colors="k")
CS = mnh.contourf(xnh, ynh, hgt, 15, cmap=P.cm.Spectral)
# colorbar on bottom.
l, b, w, h = ax.get_position()
cax = P.axes([l, b - 0.05, w, 0.025]) # setup colorbar axes
P.colorbar(cax=cax, orientation="horizontal", ticks=CS.levels[0::4]) # draw colorbar
P.axes(ax) # make the original axes current again
mnh.drawcoastlines(linewidth=0.5)
delat = 30.0
circles = P.arange(0.0, 90.0, delat).tolist() + P.arange(-delat, -90, -delat).tolist()
mnh.drawparallels(circles, labels=[1, 0, 0, 0])
delon = 45.0
meridians = P.arange(0, 360, delon)
mnh.drawmeridians(meridians, labels=[1, 0, 0, 1])
P.title("NH 500 hPa Height (cm.Spectral)")
# panel 2
示例2: Basemap
# 需要导入模块: from matplotlib.toolkits.basemap import Basemap [as 别名]
# 或者: from matplotlib.toolkits.basemap.Basemap import contourf [as 别名]
#--- Mapping information:
map = Basemap( projection='cyl', resolution='l'
, llcrnrlon=0, urcrnrlon=360
, llcrnrlat=-76.875, urcrnrlat=76.875
, lon_0=180, lat_0=0
)
map.drawmeridians(p.arange(0,361,45), labels=[0,0,0,1])
map.drawparallels(p.arange(-90,90,30), labels=[1,0,0,1])
map.drawcoastlines()
#--- Write out contour map and view using preview:
x, y = p.meshgrid(lon,lat)
CS = map.contourf(x, y, u1, cmap=p.cm.gray)
p.text( 0.5, -0.15, 'Longitude [deg]'
, horizontalalignment='center'
, verticalalignment='center'
, transform = p.gca().transAxes )
p.text( -0.11, 0.5, 'Latitude [deg]'
, rotation='vertical'
, horizontalalignment='center'
, verticalalignment='center'
, transform = p.gca().transAxes )
p.title('QTCM u1')
cbar = p.colorbar(CS, orientation='horizontal', shrink=0.6)
cbar.ax.set_xlabel('See QTCM Documentation')
p.savefig('foo.png')
os.system('preview foo.png')
示例3: meshgrid
# 需要导入模块: from matplotlib.toolkits.basemap import Basemap [as 别名]
# 或者: from matplotlib.toolkits.basemap.Basemap import contourf [as 别名]
lons, lats = meshgrid(lons1, lats1)
# plot vectors in geographical (lat/lon) coordinates.
# north polar projection.
m = Basemap(lon_0=-135,boundinglat=25,
resolution='c',area_thresh=10000.,projection='npstere')
# create a figure, add an axes.
fig=figure(figsize=(8,8))
ax = fig.add_axes([0.1,0.1,0.7,0.7])
# rotate wind vectors to map projection coordinates.
# (also compute native map projections coordinates of lat/lon grid)
# only do Northern Hemisphere.
urot,vrot,x,y = m.rotate_vector(u[36:,:],v[36:,:],lons[36:,:],lats[36:,:],returnxy=True)
# plot filled contours over map.
cs = m.contourf(x,y,p[36:,:],15,cmap=cm.jet)
# plot wind vectors over map.
Q = m.quiver(x,y,urot,vrot) #or specify, e.g., width=0.003, scale=400)
qk = quiverkey(Q, 0.95, 1.05, 25, '25 m/s', labelpos='W')
cax = axes([0.875, 0.1, 0.05, 0.7]) # setup colorbar axes.
colorbar(cax=cax) # draw colorbar
axes(ax) # make the original axes current again
m.drawcoastlines()
m.drawcountries()
# draw parallels
delat = 20.
circles = arange(0.,90.+delat,delat).tolist()+\
arange(-delat,-90.-delat,-delat).tolist()
m.drawparallels(circles,labels=[1,1,1,1])
# draw meridians
delon = 45.
示例4: geographical
# 需要导入模块: from matplotlib.toolkits.basemap import Basemap [as 别名]
# 或者: from matplotlib.toolkits.basemap.Basemap import contourf [as 别名]
# plot vectors in geographical (lat/lon) coordinates.
# north polar projection.
m = Basemap(llcrnrlon=-180.,llcrnrlat=10.,urcrnrlon=0.,urcrnrlat=10.,\
resolution='c',area_thresh=10000.,projection='stere',\
lat_0=90.,lon_0=-135.,lat_ts=90.)
# setup figure with same aspect ratio as map.
xsize = rcParams['figure.figsize'][0]
fig=figure(figsize=(xsize,m.aspect*xsize))
ax = fig.add_axes([0.1,0.1,0.7,0.7])
# rotate wind vectors to map projection coordinates.
# (also compute native map projections coordinates of lat/lon grid)
# only do Northern Hemisphere.
urot,vrot,x,y = m.rotate_vector(u[36:,:],v[36:,:],lons[36:,:],lats[36:,:],returnxy=True)
# plot filled contours over map.
levels, colls = m.contourf(x,y,p[36:,:],15,cmap=cm.jet,colors=None)
# plot wind vectors over map.
m.quiver(x,y,urot,vrot)
cax = axes([0.875, 0.1, 0.05, 0.7]) # setup colorbar axes.
colorbar(tickfmt='%d', cax=cax) # draw colorbar
axes(ax) # make the original axes current again
m.drawcoastlines()
m.drawcountries()
# draw parallels
delat = 20.
circles = arange(0.,90.+delat,delat).tolist()+\
arange(-delat,-90.-delat,-delat).tolist()
m.drawparallels(circles,labels=[1,1,1,1])
# draw meridians
delon = 45.
meridians = arange(-180,180,delon)
示例5: m
# 需要导入模块: from matplotlib.toolkits.basemap import Basemap [as 别名]
# 或者: from matplotlib.toolkits.basemap.Basemap import contourf [as 别名]
ax = fig.add_axes([0.1,0.1,0.7,0.7])
# set desired contour levels.
clevs = p.arange(960,1061,5)
# compute native x,y coordinates of grid.
x, y = m(lons, lats)
# define parallels and meridians to draw.
parallels = p.arange(-80.,90,20.)
meridians = p.arange(0.,360.,20.)
# number of repeated frames at beginning and end is n1.
nframe = 0; n1 = 10
l,b,w,h=ax.get_position()
# loop over times, make contour plots, draw coastlines,
# parallels, meridians and title.
for nt,date in enumerate(datelabels[1:]):
CS = m.contour(x,y,slp[nt,:,:],clevs,linewidths=0.5,colors='k',animated=True)
CS = m.contourf(x,y,slp[nt,:,:],clevs,cmap=p.cm.RdBu_r,animated=True)
# plot wind vectors on lat/lon grid.
# rotate wind vectors to map projection coordinates.
#urot,vrot = m.rotate_vector(u[nt,:,:],v[nt,:,:],lons,lats)
# plot wind vectors over map.
#Q = m.quiver(x,y,urot,vrot,scale=500)
# plot wind vectors on projection grid (looks better).
# first, shift grid so it goes from -180 to 180 (instead of 0 to 360
# in longitude). Otherwise, interpolation is messed up.
ugrid,newlons = shiftgrid(180.,u[nt,:,:],longitudes,start=False)
vgrid,newlons = shiftgrid(180.,v[nt,:,:],longitudes,start=False)
# transform vectors to projection grid.
urot,vrot,xx,yy = m.transform_vector(ugrid,vgrid,newlons,latitudes,51,51,returnxy=True,masked=True)
# plot wind vectors over map.
Q = m.quiver(xx,yy,urot,vrot,scale=500)
# make quiver key.
示例6: enumerate
# 需要导入模块: from matplotlib.toolkits.basemap import Basemap [as 别名]
# 或者: from matplotlib.toolkits.basemap.Basemap import contourf [as 别名]
#plots = ['contour','imshow']
for np,plot in enumerate(plots):
fig.add_subplot(1,2,np+1)
ax = gca()
# plot data.
print plot+' plot ...'
if plot == 'pcolor':
m.pcolor(x,y,hgt,shading='flat')
elif plot == 'imshow':
im = m.imshow(hgt)
elif plot == 'contour':
levels, colls = m.contour(x,y,hgt,15,linewidths=0.5,colors='k')
levels, colls = m.contourf(x,y,hgt,15,cmap=cm.jet,colors=None)
# set size of plot to match aspect ratio of map.
l,b,w,h = ax.get_position()
b = 0.5 - 0.5*w*m.aspect; h = w*m.aspect
ax.set_position([l,b,w,h])
# draw map.
m.drawcoastlines()
# draw parallels
delat = 30.
delon = 90.
circles = arange(10.,90.+delat,delat).tolist()
m.drawparallels(circles,labels=[0,0,1,1])
示例7: pickle
# 需要导入模块: from matplotlib.toolkits.basemap import Basemap [as 别名]
# 或者: from matplotlib.toolkits.basemap.Basemap import contourf [as 别名]
# read in topo data from pickle (on a regular lat/lon grid)
topodict = cPickle.load(open('etopo20.pickle','rb'))
etopo = topodict['data']; lons = topodict['lons']; lats = topodict['lats']
# create figure.
fig = Figure()
canvas = FigureCanvas(fig)
ax = fig.add_axes([0.125,0.175,0.75,0.75],frameon=False)
# create Basemap instance for Robinson projection.
# set 'ax' keyword so pylab won't be imported.
m = Basemap(projection='robin',lon_0=0.5*(lons[0]+lons[-1]),ax=ax)
# reset figure size to have same aspect ratio as map.
# fig will be 8 inches wide.
fig.set_figsize_inches((8,m.aspect*8.))
# make filled contour plot.
x, y = m(*meshgrid(lons, lats))
levels, colls = m.contourf(x,y,etopo,30,cmap=cm.jet,colors=None)
# draw coastlines.
m.drawcoastlines()
# draw a line around the map region.
m.drawmapboundary()
# draw parallels and meridians.
m.drawparallels(nx.arange(-60.,90.,30.),labels=[1,0,0,0],fontsize=10)
m.drawmeridians(nx.arange(0.,420.,60.),labels=[0,0,0,1],fontsize=10)
# add a title.
ax.set_title('Robinson Projection')
# add a colorbar.
cax = fig.add_axes([0.25, 0.05, 0.5, 0.05],frameon=False)
fig.colorbar(colls.mappable, cax=cax, tickfmt='%d', orientation='horizontal')
# save image (width 800 pixels with dpi=100 and fig width 8 inches).
canvas.print_figure('simpletest',dpi=100)
# done.
示例8: max
# 需要导入模块: from matplotlib.toolkits.basemap import Basemap [as 别名]
# 或者: from matplotlib.toolkits.basemap.Basemap import contourf [as 别名]
print max(ravel(spd))
udat, vdat, xv, yv = m.transform_vector(u,v,lons,lats,nxv,nyv,returnxy=True)
pdat, xp, yp = m.transform_scalar(p,lons,lats,nxp,nyp,returnxy=True)
print min(ravel(udat)),max(ravel(udat))
print min(ravel(vdat)),max(ravel(vdat))
print min(ravel(pdat)),max(ravel(pdat))
spd = sqrt(udat**2+vdat**2)
print max(ravel(spd))
# setup figure with same aspect ratio as map.
xsize = rcParams['figure.figsize'][0]
fig=figure(figsize=(xsize,m.aspect*xsize))
ax = fig.add_axes([0.1,0.1,0.7,0.7])
# plot filled contours over map
levels, colls = m.contourf(xp,yp,pdat,15,cmap=cm.jet,colors=None)
# plot wind vectors over map.
m.quiver(xv,yv,udat,vdat)
cax = axes([0.875, 0.1, 0.05, 0.7]) # setup colorbar axes.
colorbar(tickfmt='%d', cax=cax) # draw colorbar
axes(ax) # make the original axes current again
m.drawcoastlines()
m.drawcountries()
# draw parallels
delat = 20.
circles = arange(0.,90.+delat,delat).tolist()+\
arange(-delat,-90.-delat,-delat).tolist()
m.drawparallels(circles,labels=[1,1,1,1])
# draw meridians
delon = 45.
meridians = arange(-180,180,delon)
示例9: basemap
# 需要导入模块: from matplotlib.toolkits.basemap import Basemap [as 别名]
# 或者: from matplotlib.toolkits.basemap.Basemap import contourf [as 别名]
lons[0:len(lonsin)] = lonsin-0.5*delon
lons[-1] = lonsin[-1]+0.5*delon
lats[0:len(latsin)] = latsin-0.5*delat
lats[-1] = latsin[-1]+0.5*delat
# setup of basemap ('ortho' = orthographic projection)
m = Basemap(projection='ortho',
resolution='c',area_thresh=10000.,lat_0=30,lon_0=-60)
fig=m.createfigure()
ax = fig.add_axes([0.1,0.1,0.7,0.7])
# pcolor plot (slow)
#x,y = m(*meshgrid(lons,lats))
#p = m.pcolor(x,y,topodatin,shading='flat')
# filled contours (faster)
x,y = m(*meshgrid(lonsin,latsin))
cs = m.contourf(x,y,topodatin,20,cmap=cm.jet)
cax = axes([0.875, 0.1, 0.05, 0.7]) # setup colorbar axes
colorbar(tickfmt='%d', cax=cax) # draw colorbar
axes(ax) # make the original axes current again
# draw coastlines and political boundaries.
m.drawcoastlines()
# draw parallels and meridians (labelling is
# not implemented for orthographic).
parallels = arange(-80.,90,20.)
m.drawparallels(parallels)
meridians = arange(0.,360.,20.)
m.drawmeridians(meridians)
# draw boundary around map region.
m.drawmapboundary()
title('Orthographic')
print 'plotting Orthographic example, close plot window to proceed ...'
示例10: plot_ncdf_output
# 需要导入模块: from matplotlib.toolkits.basemap import Basemap [as 别名]
# 或者: from matplotlib.toolkits.basemap.Basemap import contourf [as 别名]
#.........这里部分代码省略.........
elif N.size(rngs_idxs['lon']) == 1:
zgrid = num.MLab.squeeze(data[ ritim[0]:ritim[-1]+1,
rilat[0]:rilat[-1]+1,
rilon[0] ])
else:
raise ValueError, 'unrecognized configuration'
#* Change zgrid for special case of a lat. vs. time contour
# plot. Calculate xgrid and ygrid:
if keys_rngs_sizes_gt_1.count('time') and \
keys_rngs_sizes_gt_1.count('lat'):
zgrid = N.transpose(zgrid)
xgrid, ygrid = pylab.meshgrid(x, y)
#* Set contour levels:
if plotkwds['levels'] == None:
levels = nice_levels(zgrid)
else:
levels = plotkwds['levels']
#- Plot (creating continents first if is a lat vs. lon plot)
# and write contour levels/color bar as appropriate:
if keys_rngs_sizes_gt_1.count('lon') and \
keys_rngs_sizes_gt_1.count('lat'):
mapplot = Basemap(projection='cyl', resolution='l',
llcrnrlon=N.min(xgrid), llcrnrlat=N.min(ygrid),
urcrnrlon=N.max(xgrid), urcrnrlat=N.max(ygrid))
mapplot.drawcoastlines()
mapplot.drawmeridians(nice_levels(rngs['lon'],
approx_nlev=plotkwds['nlatlon']),
labels=[1,0,0,1])
mapplot.drawparallels(nice_levels(rngs['lat'],
approx_nlev=plotkwds['nlatlon']),
labels=[1,0,0,1])
if plotkwds['filled']:
plot = mapplot.contourf(xgrid, ygrid, zgrid, levels)
pylab.colorbar(plot, orientation='horizontal', format='%g')
else:
plot = mapplot.contour(xgrid, ygrid, zgrid, levels)
pylab.clabel(plot, inline=1, fontsize=10, fmt='%g')
else:
if plotkwds['filled']:
plot = pylab.contourf(xgrid, ygrid, zgrid, levels)
pylab.colorbar(plot, orientation='horizontal', format='%g')
else:
plot = pylab.contour(xgrid, ygrid, zgrid, levels)
pylab.clabel(plot, inline=1, fontsize=10, fmt='%g')
else:
raise ValueError, 'unrecognized plottype'
#- Add titling. Lat vs. lon plots do not have axis labels because
# the map labels already make it clear, and for those plots the
# title also includes the time value:
if keys_rngs_sizes_gt_1.count('lon') and \
keys_rngs_sizes_gt_1.count('lat'):
titlename = titlename + ' at ' \
+ dimname['time'] + ' ' \
+ str(rngs['time'][0]) + ' ' \
+ dimunits['time']
titlename = mpl_latex_script1(titlename)
pylab.title(titlename)
else:
titlename = mpl_latex_script1(titlename)
xname = mpl_latex_script1(xname)
yname = mpl_latex_script1(yname)
pylab.xlabel(xname)
pylab.ylabel(yname)
pylab.title(titlename)
#- Output plot to PNG file or screen. The show command seems to
# have a problem on my Mac OS X, so save to a temporary file
# and use preview to view for fn == None and tmppreview set to
# True. Note that the temporary file is not deleted by this
# method:
if plotkwds['fn'] == None: #+ Screen display
if plotkwds['tmppreview'] and sys.platform == 'darwin':
outputfn = tempfile.mkstemp('.png','qtcm_')
pylab.savefig(outputfn[-1])
os.system('open -a /Applications/Preview.app '+outputfn[-1])
else:
pylab.show()
elif type(plotkwds['fn']) == type('a'): #+ Write to file
pylab.savefig(plotkwds['fn'])
pylab.close(1)
else:
raise ValueError, 'cannot write to this type of file'
示例11: figure
# 需要导入模块: from matplotlib.toolkits.basemap import Basemap [as 别名]
# 或者: from matplotlib.toolkits.basemap.Basemap import contourf [as 别名]
cdict = {'red': ((0.,)*3,(.5,1.,1.),(1.,1.,1.)),
'green': ((0.,)*3,(.5,1.,1.),(1.,0.,0.)),
'blue': ((0.,1.,1.),(.5,1.,1.),(1.,0.,0.))}
return matplotlib.colors.LinearSegmentedColormap('bwr',cdict,256)
figure(figsize=(8,8))
subplot(ncol,nrow,nslice)
for i in xrange(nslice):
lon = composites.getLongitude()
lat = composites.getLatitude()
xx,yy = meshgrid(lon,lat)
m = Basemap(resolution='l',lat_0=N.average(lat),lon_0=N.average(lon),
llcrnrlon=min(lon),llcrnrlat=min(lat),
urcrnrlon=max(lon),urcrnrlat=max(lat))
levels = vcs.mkscale(genutil.minmax(composites))
m.contourf(lon,lat,composites[i],levels=levels,cmap=bwr)
clabel(m.contour(lon,lat,composites[i],levels=levels))
title("Phase %i/%i" (i+1,6))
m.drawcoastlines()
m.drawcountries()
m.fillcontinents(color='coral')
m.drawparallels(vcs.mkscale(genutil.minmax(lat)),labels=[1,0,0,0])
m.drawmeridians(vcs.mkscale(genutil.minmax(lon)),labels=[0,0,0,1])
figtext(.5,1.,"\n%s [%s]" % ("El Nino phase composites\nSea surface temperature", composites.units))
savefig(sys.argv[0].replace(".py",".png"))
show()
# Fall back to vcs because we have it!
except:
# Plot 1 phase over two, then a time series
示例12: load
# 需要导入模块: from matplotlib.toolkits.basemap import Basemap [as 别名]
# 或者: from matplotlib.toolkits.basemap.Basemap import contourf [as 别名]
hgt = load('500hgtdata.gz')
lons = load('500hgtlons.gz')
lats = load('500hgtlats.gz')
# shift data so lons go from -180 to 180 instead of 0 to 360.
hgt,lons = shiftgrid(180.,hgt,lons,start=False)
lons, lats = meshgrid(lons, lats)
# create new figure
fig=figure()
# setup of sinusoidal basemap
m = Basemap(resolution='c',projection='sinu',lon_0=0)
ax = fig.add_axes([0.1,0.1,0.7,0.7])
# make a filled contour plot.
x, y = m(lons, lats)
CS = m.contour(x,y,hgt,15,linewidths=0.5,colors='k')
CS = m.contourf(x,y,hgt,15,cmap=cm.jet)
l,b,w,h=ax.get_position()
cax = axes([l+w+0.075, b, 0.05, h]) # setup colorbar axes
colorbar(drawedges=True, cax=cax) # draw colorbar
axes(ax) # make the original axes current again
# draw coastlines and political boundaries.
m.drawcoastlines()
m.drawmapboundary()
m.fillcontinents()
# draw parallels and meridians.
parallels = arange(-60.,90,30.)
m.drawparallels(parallels,labels=[1,0,0,0])
meridians = arange(-360.,360.,30.)
m.drawmeridians(meridians)
title('Sinusoidal Filled Contour Demo')
print 'plotting with sinusoidal basemap ...'
示例13: data
# 需要导入模块: from matplotlib.toolkits.basemap import Basemap [as 别名]
# 或者: from matplotlib.toolkits.basemap.Basemap import contourf [as 别名]
# read in topo data (on a regular lat/lon grid)
# longitudes go from 20 to 380.
etopo = load('etopo20data.gz')
lons = load('etopo20lons.gz')
lats = load('etopo20lats.gz')
# create figure.
fig = Figure()
canvas = FigureCanvas(fig)
# create axes instance, leaving room for colorbar at bottom.
ax = fig.add_axes([0.125,0.175,0.75,0.75])
# create Basemap instance for Robinson projection.
# set 'ax' keyword so pylab won't be imported.
m = Basemap(projection='robin',lon_0=0.5*(lons[0]+lons[-1]),ax=ax)
# make filled contour plot.
x, y = m(*meshgrid(lons, lats))
cs = m.contourf(x,y,etopo,30,cmap=cm.jet)
# draw coastlines.
m.drawcoastlines()
# draw a line around the map region.
m.drawmapboundary()
# draw parallels and meridians.
m.drawparallels(nx.arange(-60.,90.,30.),labels=[1,0,0,0],fontsize=10)
m.drawmeridians(nx.arange(0.,420.,60.),labels=[0,0,0,1],fontsize=10)
# add a title.
ax.set_title('Robinson Projection')
# add a colorbar.
l,b,w,h = ax.get_position()
cax = fig.add_axes([l, b-0.1, w, 0.03],frameon=False) # setup colorbar axes
fig.colorbar(cs, cax=cax, orientation='horizontal',ticks=cs.levels[::3])
# save image (width 800 pixels with dpi=100 and fig width 8 inches).
canvas.print_figure('simpletest',dpi=100)