Menu

[r3080]: / trunk / toolkits / basemap / examples / panelplot.py  Maximize  Restore  History

Download this file

98 lines (86 with data), 3.5 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
from matplotlib.toolkits.basemap import Basemap
from matplotlib import rcParams
from matplotlib.ticker import MultipleLocator
import pylab as P
# read in data on lat/lon grid.
hgt = P.load('500hgtdata.gz')
lons = P.load('500hgtlons.gz')
lats = P.load('500hgtlats.gz')
lons, lats = P.meshgrid(lons, lats)
# 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.,
resolution='c',area_thresh=10000.,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.
circles = P.arange(0.,90.,delat).tolist()+\
P.arange(-delat,-90,-delat).tolist()
mnh.drawparallels(circles,labels=[1,0,0,0])
delon = 45.
meridians = P.arange(0,360,delon)
mnh.drawmeridians(meridians,labels=[1,0,0,1])
P.title('NH 500 hPa Height (cm.Spectral)')
# panel 2
msh = Basemap(lon_0=-105,boundinglat=-20.,
resolution='c',area_thresh=10000.,projection='splaea')
xsh,ysh = msh(lons,lats)
ax = fig.add_subplot(212)
CS = msh.contour(xsh,ysh,hgt,15,linewidths=0.5,colors='k')
CS = msh.contourf(xsh,ysh,hgt,15,cmap=P.cm.Spectral)
# colorbar on bottom.
ax.apply_aspect()
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=MultipleLocator(320)) # draw colorbar
P.axes(ax) # make the original axes current again
msh.drawcoastlines(linewidth=0.5)
msh.drawparallels(circles,labels=[1,0,0,0])
msh.drawmeridians(meridians,labels=[1,0,0,1])
P.title('SH 500 hPa Height (cm.Spectral)')
# 2-panel plot, oriented horizontally, colorbar on right.
# adjust default subplot parameters a bit
rcParams['figure.subplot.left'] = 0.1 # move left edge of subplot over a bit
rcParams['figure.subplot.right'] = 0.85
rcParams['figure.subplot.top'] = 0.85
# panel 1
fig = P.figure()
ax = fig.add_subplot(121)
CS = mnh.contour(xnh,ynh,hgt,15,linewidths=0.5,colors='k')
CS = mnh.contourf(xnh,ynh,hgt,15,cmap=P.cm.RdBu)
# colorbar on right
l,b,w,h = ax.get_position()
cax = P.axes([l+w+0.025, b, 0.025, h]) # setup colorbar axes
P.colorbar(cax=cax, ticks=MultipleLocator(160), format='%4i') # draw colorbar
P.axes(ax) # make the original axes current again
mnh.drawcoastlines(linewidth=0.5)
mnh.drawparallels(circles,labels=[1,0,0,0])
mnh.drawmeridians(meridians,labels=[1,0,0,1])
P.title('NH 500 hPa Height (cm.RdBu)')
# panel 2
ax = fig.add_subplot(122)
CS = msh.contour(xsh,ysh,hgt,15,linewidths=0.5,colors='k')
CS = msh.contourf(xsh,ysh,hgt,15,cmap=P.cm.RdBu)
# colorbar on right.
l,b,w,h = ax.get_position()
cax = P.axes([l+w+0.025, b, 0.025, h]) # setup colorbar axes
P.colorbar(cax=cax, ticks=MultipleLocator(160), format='%4i') # draw colorbar
P.axes(ax) # make the original axes current again
msh.drawcoastlines(linewidth=0.5)
msh.drawparallels(circles,labels=[1,0,0,0])
msh.drawmeridians(meridians,labels=[1,0,0,1])
P.title('SH 500 hPa Height (cm.RdBu)')
P.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.