Menu

[r1961]: / trunk / htdocs / screenshots / contour_shot.py  Maximize  Restore  History

Download this file

59 lines (42 with data), 1.6 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from matplotlib.toolkits.basemap import Basemap, interp
from pylab import *
import cPickle
# read in data on lat/lon grid.
datadict = cPickle.load(file('/home/jdhunter/python/projects/toolkits/basemap/examples/500hgt.pickle','rb'))
hgt = datadict['data']; lons = datadict['lons']; lats = datadict['lats']
# set up map projection (lambert azimuthal equal area).
m = Basemap(-135.,-20.,45.,-20.,
resolution='c',area_thresh=10000.,projection='laea',
lat_0=90.,lon_0=-90.)
# interpolate to map projection grid.
nx = 101
ny = 101
lonsout, latsout = m.makegrid(nx,ny)
# get rid of negative lons.
lonsout = where(lonsout < 0., lonsout + 360., lonsout)
hgt = interp(hgt,lons,lats,lonsout,latsout)
dx = (m.xmax-m.xmin)/(nx-1)
dy = (m.ymax-m.ymin)/(ny-1)
x = m.llcrnrx+dx*indices((ny,nx))[1,:,:]
y = m.llcrnry+dy*indices((ny,nx))[0,:,:]
cmap = cm.jet
fig = figure(figsize=(6,6))
ax = fig.add_axes([0.1, 0.1, 0.8, 0.8])
levels, colls = contour(x,y,hgt,15,linewidths=0.5,colors='k')
levels, colls = contourf(x,y,hgt,15,cmap=cmap,colors=None)
corners = ((m.xmin,m.ymin), (m.xmax,m.ymax))
ax.update_datalim( corners )
axis([m.xmin, m.xmax, m.ymin, m.ymax])
# draw map.
m.drawcoastlines(ax)
# draw parallels
delat = 30.
delon = 90.
circles = arange(10.,90.+delat,delat).tolist()
m.drawparallels(ax,circles,labels=[0,0,1,1], fontsize=16)
# draw meridians
meridians = arange(0.,360.,delon)
m.drawmeridians(ax,meridians,labels=[1,1,1,1],fontsize=16)
savefig('contour_small.png', dpi=50)
savefig('contour_large', dpi=120)
show()
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.