本文整理汇总了Python中matplotlib.toolkits.basemap.Basemap.drawmeridians方法的典型用法代码示例。如果您正苦于以下问题:Python Basemap.drawmeridians方法的具体用法?Python Basemap.drawmeridians怎么用?Python Basemap.drawmeridians使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.toolkits.basemap.Basemap
的用法示例。
在下文中一共展示了Basemap.drawmeridians方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: InvokeMap
# 需要导入模块: from matplotlib.toolkits.basemap import Basemap [as 别名]
# 或者: from matplotlib.toolkits.basemap.Basemap import drawmeridians [as 别名]
def InvokeMap(coastfile='/media/sda4/map-data/aust-coast-noaa-2000000-1.dat',
lllon=80,
urlon=166,
lllat=-47,
urlat=-9,
draw_map=True):
global PYLIB_PATH
map = Basemap(projection='cyl',
llcrnrlon=lllon,
urcrnrlon=urlon,
llcrnrlat=lllat,
urcrnrlat=urlat,
#lat_ts=-35,
lat_0=-35,
lon_0=120,
resolution='l',
area_thresh=1000.)
try:
coast = p.load(coastfile)
coast = p.load(coastfile)
coast_x,coast_y = map(coast[:,0],coast[:,1])
p.plot(coast_x,coast_y,color='black')
except IOError:
map.drawcoastlines()
map.drawmapboundary()
map.drawmeridians(p.arange(0,360,10),labels=[0,0,1,0])
map.drawparallels(p.arange(-90,0,10),labels=[1,0,0,0])
return map
示例2: doit
# 需要导入模块: from matplotlib.toolkits.basemap import Basemap [as 别名]
# 或者: from matplotlib.toolkits.basemap.Basemap import drawmeridians [as 别名]
def doit():
map = Basemap(projection='lcc',
llcrnrlon=80,
urcrnrlon=160,
llcrnrlat=-50,
urcrnrlat=-8,
#lat_ts=-35,
lat_0=-35,
lon_0=120,
resolution='c',
area_thresh=1000.)
p.clf()
map.drawcoastlines()
# map.drawcountries()
# map.drawrivers()
map.drawmeridians(p.arange(0,360,10),labels=[0,0,1,0])
map.drawparallels(p.arange(-90,0,10),labels=[1,0,0,0])
traj=p.load('example_traj.dat')
coast=p.load('/media/sda4/map-data/aust-coast-noaa-2000000-1.dat')
traj_x,traj_y = map(traj[:,1],traj[:,0])
# coast_x,coast_y = map(coast[:,0],coast[:,1])
p.plot(traj_x,traj_y)
p.plot(coast_x,coast_y,color='black')
map.drawmapboundary()
p.show()
return map
示例3: draw_graph_on_map
# 需要导入模块: from matplotlib.toolkits.basemap import Basemap [as 别名]
# 或者: from matplotlib.toolkits.basemap.Basemap import drawmeridians [as 别名]
def draw_graph_on_map(g, node2weight, node2pos, pic_title, pic_area=[-130,10,140,70], output_fname_prefix=None, need_draw_edge=0):
"""
2007-09-13
identity_pair_ls is a list of pairs of strains (ecotype id as in table ecotype)
2007-10-08
correct a bug in 4*diameter_ls, diameter_ls has to be converted to array first.
sqrt the node weight, 8 times the original weight
"""
import os, sys
sys.stderr.write("Drawing graph on a map ...\n")
import pylab, math
from matplotlib.toolkits.basemap import Basemap
pylab.clf()
fig = pylab.figure()
fig.add_axes([0.05,0.05,0.9,0.9]) #[left, bottom, width, height]
m = Basemap(llcrnrlon=pic_area[0],llcrnrlat=pic_area[1],urcrnrlon=pic_area[2],urcrnrlat=pic_area[3],\
resolution='l',projection='mill', ax=pylab.gca())
sys.stderr.write("\tDrawing nodes ...")
euc_coord1_ls = []
euc_coord2_ls = []
diameter_ls = []
for n in g.nodes():
lat, lon = node2pos[n]
euc_coord1, euc_coord2 = m(lon, lat) #longitude first, latitude 2nd
euc_coord1_ls.append(euc_coord1)
euc_coord2_ls.append(euc_coord2)
diameter_ls.append(math.sqrt(node2weight[n]))
import numpy
diameter_ls = numpy.array(diameter_ls)
m.scatter(euc_coord1_ls, euc_coord2_ls, 8*diameter_ls, marker='o', color='r', alpha=0.4, zorder=12, faceted=False)
sys.stderr.write("Done.\n")
if need_draw_edge:
sys.stderr.write("\tDrawing edges ...")
ax=pylab.gca()
for popid1, popid2, no_of_connections in g.edges():
lat1, lon1 = node2pos[popid1]
lat2, lon2 = node2pos[popid2]
x1, y1 = m(lon1, lat1)
x2, y2 = m(lon2, lat2)
ax.plot([x1,x2],[y1,y2], 'g', linewidth=math.log(no_of_connections+1)/2, alpha=0.2, zorder=10)
sys.stderr.write("Done.\n")
#m.drawcoastlines()
m.drawparallels(pylab.arange(-90,90,30), labels=[1,1,0,1])
m.drawmeridians(pylab.arange(-180,180,30), labels=[1,1,0,1])
m.fillcontinents()
m.drawcountries()
m.drawstates()
pylab.title(pic_title)
if output_fname_prefix:
pylab.savefig('%s.eps'%output_fname_prefix, dpi=600)
pylab.savefig('%s.svg'%output_fname_prefix, dpi=600)
pylab.savefig('%s.png'%output_fname_prefix, dpi=600)
del fig, m, pylab
sys.stderr.write("Done.\n")
示例4: draw_clustered_strain_location
# 需要导入模块: from matplotlib.toolkits.basemap import Basemap [as 别名]
# 或者: from matplotlib.toolkits.basemap.Basemap import drawmeridians [as 别名]
def draw_clustered_strain_location(self, label_ls, weighted_pos_ls, diameter_ls, label_type, label_type2label_name, pic_area=[-180,-90,180,90], output_fname_prefix=None, label_name=None):
"""
2007-07-11
draw populations derived from connected_components of the strain network
#each pie denotes a population, with diameter proportional to the size of the population
#each pie labeled with the number of strains in that population
2007-07-13
use popid as label
2007-07-17
no parallels, no meridians
2007-08-29
copied from CreatePopulation.py
2007-09-11
add label name
2007-10-14
correct a bug in 5*diameter_ls. diameter_ls has to an array
"""
sys.stderr.write("Drawing population map...")
import pylab
from matplotlib.toolkits.basemap import Basemap
pylab.clf()
fig = pylab.figure()
fig.add_axes([0.05,0.05,0.9,0.9]) #[left, bottom, width, height]
m = Basemap(llcrnrlon=pic_area[0],llcrnrlat=pic_area[1],urcrnrlon=pic_area[2],urcrnrlat=pic_area[3],\
resolution='l',projection='mill')
euc_coord1_ls = []
euc_coord2_ls = []
ax=pylab.gca()
for i in range(len(weighted_pos_ls)):
lat, lon = weighted_pos_ls[i]
euc_coord1, euc_coord2 = m(lon, lat) #longitude first, latitude 2nd
euc_coord1_ls.append(euc_coord1)
euc_coord2_ls.append(euc_coord2)
ax.text(euc_coord1, euc_coord2, str(label_ls[i]), size=5, alpha=0.5, horizontalalignment='center', verticalalignment='center', zorder=12)
import numpy
diameter_ls = numpy.array(diameter_ls)
m.scatter(euc_coord1_ls, euc_coord2_ls, 5*diameter_ls, marker='o', color='r', alpha=0.3, zorder=10, faceted=False)
#m.drawcoastlines()
m.drawparallels(pylab.arange(-90,90,30), labels=[1,1,0,1]) #labels intersect the left, right, top bottom of the plot
m.drawmeridians(pylab.arange(-180,180,30), labels=[1,1,0,1])
m.fillcontinents()
m.drawcountries()
m.drawstates()
pylab.title("worldwide distribution of %s populations, labeled by %s"%(len(weighted_pos_ls), label_type2label_name[label_type]))
if output_fname_prefix:
pylab.savefig('%s_pop_map.eps'%output_fname_prefix, dpi=300)
pylab.savefig('%s_pop_map.svg'%output_fname_prefix, dpi=300)
pylab.savefig('%s_pop_map.png'%output_fname_prefix, dpi=300)
del m, pylab, Basemap
sys.stderr.write("Done.\n")
示例5: DrawSiteNetwork
# 需要导入模块: from matplotlib.toolkits.basemap import Basemap [as 别名]
# 或者: from matplotlib.toolkits.basemap.Basemap import drawmeridians [as 别名]
def DrawSiteNetwork(self, g, node_label2pos_counts,pic_area=[-180,-90,180,90], output_fname_prefix=None):
"""
2007-07-17
put ax.plot() right after Basemap() but after m.xxx() so that it'll zoom in
use 'g' in ax.plot(), otherwise, ax.plot() alternates all colors.
no parallels, no meridians
2007-08-29 copied from CreatePopulation.py and renamed from DrawStrainNetwork
"""
sys.stderr.write("Drawing Site Network...")
import pylab
from matplotlib.toolkits.basemap import Basemap
pylab.clf()
fig = pylab.figure()
fig.add_axes([0.05,0.05,0.9,0.9]) #[left, bottom, width, height]
m = Basemap(llcrnrlon=pic_area[0],llcrnrlat=pic_area[1],urcrnrlon=pic_area[2],urcrnrlat=pic_area[3],\
resolution='l',projection='mill')
ax=pylab.gca()
for e in g.edges():
lat1, lon1 = node_label2pos_counts[e[0]][0]
lat2, lon2 = node_label2pos_counts[e[1]][0]
x1, y1 = m(lon1, lat1)
x2, y2 = m(lon2, lat2)
ax.plot([x1,x2],[y1,y2], 'g', alpha=0.5, zorder=12)
#m.drawcoastlines()
m.drawparallels(pylab.arange(-90,90,30), labels=[1,1,0,1])
m.drawmeridians(pylab.arange(-180,180,30), labels=[1,1,0,1])
m.fillcontinents()
m.drawcountries()
m.drawstates()
pylab.title("Network of strains")
if output_fname_prefix:
pylab.savefig('%s_site_network.eps'%output_fname_prefix, dpi=300)
pylab.savefig('%s_site_network.svg'%output_fname_prefix, dpi=300)
pylab.savefig('%s_site_network.png'%output_fname_prefix, dpi=300)
del m, pylab, Basemap
sys.stderr.write("Done.\n")
示例6: region
# 需要导入模块: from matplotlib.toolkits.basemap import Basemap [as 别名]
# 或者: from matplotlib.toolkits.basemap.Basemap import drawmeridians [as 别名]
# in which direction to depart for other points on earth and how far
# it will be to reach that destination.
# The specified point shows up as a red dot in the center of the map.
# This example shows how to use the width and height keywords
# to specify the map projection region (instead of specifying
# the lat/lon of the upper right and lower left corners).
# user enters the lon/lat of the point, and it's name
lon_0 = float(raw_input('input reference lon (degrees):'))
lat_0 = float(raw_input('input reference lat (degrees):'))
location = raw_input('name of location:')
# use these values to setup Basemap instance.
width = 28000000
m = Basemap(width=width,height=width,\
resolution='c',projection='aeqd',\
lat_0=lat_0,lon_0=lon_0)
# draw coasts and fill continents.
m.drawcoastlines(linewidth=0.5)
m.fillcontinents()
# 20 degree graticule.
m.drawparallels(arange(-80,81,20))
m.drawmeridians(arange(-180,180,20))
# draw a red dot at the center.
xpt, ypt = m(lon_0, lat_0)
m.plot([xpt],[ypt],'ro')
# draw the title.
title('The World According to Garp in '+location)
show()
示例7: Basemap
# 需要导入模块: from matplotlib.toolkits.basemap import Basemap [as 别名]
# 或者: from matplotlib.toolkits.basemap.Basemap import drawmeridians [as 别名]
# Lambert Conformal map of lower 48 states.
m = Basemap(llcrnrlon=-119,llcrnrlat=22,urcrnrlon=-64,urcrnrlat=49,
projection='lcc',lat_1=33,lat_2=45,lon_0=-95)
fig=p.figure(figsize=(8,m.aspect*8))
fig.add_axes([0.1,0.1,0.8,0.8])
# draw climate division boundaries.
shp_info = m.readshapefile('divisions','climdivs',drawbounds=True)
print shp_info
# make sure the shapefile has polygons (and not just lines).
if shp_info[1] != 5:
print 'warning: shapefile does not contain polygons'
# choose a color for each climate division (randomly).
colors={}
divnames=[]
print m.climdivs_info[0].keys()
for shapedict in m.climdivs_info:
divname = shapedict['ST']+repr(shapedict['DIV'])
colors[divname] = (random.uniform(0,1),random.uniform(0,1),random.uniform(0,1))
divnames.append(divname)
# cycle through climate divnames, color each one.
for nshape,seg in enumerate(m.climdivs):
xx,yy = zip(*seg)
color = rgb2hex(colors[divnames[nshape]])
p.fill(xx,yy,color,edgecolor=color)
# draw meridians and parallels.
m.drawparallels(nx.arange(25,65,20),labels=[1,0,0,0])
m.drawmeridians(nx.arange(-120,-40,20),labels=[0,0,0,1])
p.title('NCDC Climate Divisions')
p.show()
示例8: plot_ncdf_output
# 需要导入模块: from matplotlib.toolkits.basemap import Basemap [as 别名]
# 或者: from matplotlib.toolkits.basemap.Basemap import drawmeridians [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'
示例9: axes
# 需要导入模块: from matplotlib.toolkits.basemap import Basemap [as 别名]
# 或者: from matplotlib.toolkits.basemap.Basemap import drawmeridians [as 别名]
cax = axes([0.875, 0.1, 0.05, 0.75]) # setup colorbar axes.
colorbar(tickfmt='%d', cax=cax) # draw colorbar
axes(ax) # make the original axes current again
m.drawcoastlines()
#m.drawcountries()
#m.drawstates()
#m.fillcontinents()
# draw parallels
delat = 30.
circles = arange(0.,90.+delat,delat).tolist()+\
arange(-delat,-90.-delat,-delat).tolist()
m.drawparallels(circles,labels=[1,0,0,1])
# draw meridians
delon = 60.
meridians = arange(-180,180,delon)
m.drawmeridians(meridians,labels=[1,0,0,1])
title('Cylindrical Equidistant')
print 'plotting Cylindrical Equidistant example, close plot window to proceed ...'
show()
# setup miller cylindrical map projection.
m = Basemap(-180.,-90.,180.,90.,\
resolution='c',area_thresh=10000.,projection='mill')
# transform to nx x ny regularly spaced native projection grid
nx = len(lons); ny = len(lats)
topodat = m.transform_scalar(topoin,lons,lats,nx,ny)
# setup figure with same aspect ratio as map.
xsize = rcParams['figure.figsize'][0]
fig=figure(figsize=(xsize,m.aspect*xsize))
fig.add_axes([0.1,0.1,0.75,0.75])
# plot image over map.
示例10: int
# 需要导入模块: from matplotlib.toolkits.basemap import Basemap [as 别名]
# 或者: from matplotlib.toolkits.basemap.Basemap import drawmeridians [as 别名]
resolution='c',area_thresh=10000.,projection='lcc',\
lat_1=50.,lon_0=-107.)
# transform to nx x ny regularly spaced native projection grid
nx = int((m.xmax-m.xmin)/40000.)+1; ny = int((m.ymax-m.ymin)/40000.)+1
topodat = m.transform_scalar(topoin,lons,lats,nx,ny)
# set up 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 image over map.
im = m.imshow(topodat,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
m.drawcoastlines()
m.drawcountries()
m.drawstates()
#m.fillcontinents()
# draw parallels
delat = 20.
parallels = arange(0.,90.+delat,delat).tolist()+\
arange(-delat,-90.-delat,-delat).tolist()
m.drawparallels(parallels,labels=[1,1,0,1]) # labels on left, right, bottom.
# draw meridians
delon = 30.
meridians = arange(10.,360.,delon)
m.drawmeridians(meridians,labels=[1,1,0,1]) # labels on left, right, bottom.
title('ETOPO Topography - Lambert Conformal Conic')
show()
示例11: pickle
# 需要导入模块: from matplotlib.toolkits.basemap import Basemap [as 别名]
# 或者: from matplotlib.toolkits.basemap.Basemap import drawmeridians [as 别名]
from matplotlib.toolkits.basemap import Basemap
import cPickle
from pylab import *
# 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 Basemap instance (global cylindrical equidistant is default)
m = Basemap(lons[0],lats[0],lons[-1],lats[-1])
# create figure with same aspect ratio as map.
xsize = rcParams['figure.figsize'][0]
fig=figure(figsize=(xsize,m.aspect*xsize))
fig.add_axes([0.1,0.1,0.8,0.8])
im = m.imshow(etopo)
# draw coastlines and fill continents.
m.drawcoastlines()
m.fillcontinents()
# draw parallels, label on bottom.
circles = arange(-90.,120.,30.)
m.drawparallels(circles,labels=[1,0,0,0])
# draw meridians, label on left.
meridians = arange(0.,390.,60.)
m.drawmeridians(meridians,labels=[0,0,0,1])
title('Cylindrical Equidistant')
show()
示例12: gca
# 需要导入模块: from matplotlib.toolkits.basemap import Basemap [as 别名]
# 或者: from matplotlib.toolkits.basemap.Basemap import drawmeridians [as 别名]
xsize = rcParams['figure.figsize'][0]
fig=figure(figsize=(xsize,m.aspect*xsize))
fig.add_axes([0.1,0.1,0.8,0.8])
ax = gca() # get current axis instance
ax.update_datalim(((m.llcrnrx, m.llcrnry),(m.urcrnrx,m.urcrnry)))
ax.set_xlim((m.llcrnrx, m.urcrnrx))
ax.set_ylim((m.llcrnry, m.urcrnry))
m.drawcoastlines(ax)
m.drawcountries(ax)
m.drawstates(ax)
m.fillcontinents(ax)
# draw parallels
delat = 30.
circles = arange(0.,90.,delat).tolist()+\
arange(-delat,-90,-delat).tolist()
m.drawparallels(ax,circles)
# convert parallels to native map projection coordinates
nativeCoordCircles = m([0]*len(circles), circles)[1]
ax.set_yticks(nativeCoordCircles)
ax.yaxis.set_major_formatter(MercYAxisFormatter(m))
# draw meridians
delon = 60.
lon1 = int(m.llcrnrlon/delon)*delon
lon2 = (int(m.urcrnrlon/delon)+1)*delon
meridians = arange(lon1,lon2,delon)
m.drawmeridians(ax,meridians)
ax.set_xticks(meridians)
title('Mercator with Longitude and Latitude Labels')
print 'plotting Mercator Y-axis latitude ticks example, close plot window to proceed ...'
show()
示例13: Geostationary
# 需要导入模块: from matplotlib.toolkits.basemap import Basemap [as 别名]
# 或者: from matplotlib.toolkits.basemap.Basemap import drawmeridians [as 别名]
from matplotlib.toolkits.basemap import Basemap
from pylab import title, show, arange
# create Basemap instance for Geostationary (satellite view) projection.
lon_0 = float(raw_input('enter reference longitude (lon_0):'))
h = float(raw_input('enter satellite height above equator in meters (satellite_height):'))
m = Basemap(projection='geos',lon_0=lon_0,satellite_height=h,rsphere=(6378137.00,6356752.3142),)
# plot land-sea mask.
rgba_land = (0,255,0,255) # land green.
rgba_ocean = (0,0,255,255) # ocean blue.
# lakes=True means plot inland lakes with ocean color.
m.drawlsmask(rgba_land, rgba_ocean, lakes=True)
# draw parallels and meridians.
m.drawparallels(arange(-90.,120.,30.))
m.drawmeridians(arange(0.,420.,60.))
m.drawmapboundary()
title('Geostationary Map Centered on Lon=%s, Satellite Height=%s' % (lon_0,h))
show()
示例14: grid
# 需要导入模块: from matplotlib.toolkits.basemap import Basemap [as 别名]
# 或者: from matplotlib.toolkits.basemap.Basemap import drawmeridians [as 别名]
#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.
qk = p.quiverkey(Q, 0.1, 0.1, 20, '20 m/s', labelpos='W')
# draw coastlines, parallels, meridians, title.
m.drawcoastlines(linewidth=1.5)
m.drawparallels(parallels)
m.drawmeridians(meridians)
p.title('SLP and Wind Vectors '+date)
if nt == 0: # plot colorbar on a separate axes (only for first frame)
cax = p.axes([l+w-0.05, b, 0.03, h]) # setup colorbar axes
fig.colorbar(CS,drawedges=True, cax=cax) # draw colorbar
cax.text(0.0,-0.05,'mb')
p.axes(ax) # reset current axes
p.draw() # draw the plot
# save first and last frame n1 times
# (so gif animation pauses at beginning and end)
if nframe == 0 or nt == slp.shape[0]-1:
for n in range(n1):
p.savefig('anim%03i'%nframe+'.png')
nframe = nframe + 1
else:
p.savefig('anim%03i'%nframe+'.png')
示例15: data
# 需要导入模块: from matplotlib.toolkits.basemap import Basemap [as 别名]
# 或者: from matplotlib.toolkits.basemap.Basemap import drawmeridians [as 别名]
from matplotlib.toolkits.basemap import Basemap
from pylab import *
# read in topo data (on a regular lat/lon grid)
etopo=array(load('etopo20data.gz'),'d')
lons=array(load('etopo20lons.gz'),'d')
lats=array(load('etopo20lats.gz'),'d')
# create Basemap instance for Robinson projection.
m = Basemap(projection='robin',lon_0=0.5*(lons[0]+lons[-1]))
# create figure with same aspect ratio as map.
fig = m.createfigure()
# 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(arange(-60.,90.,30.),labels=[1,0,0,0])
m.drawmeridians(arange(0.,420.,60.),labels=[0,0,0,1])
# add a title.
title('Robinson Projection')
show()