Menu

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

Download this file

103 lines (91 with data), 3.7 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
 98
 99
100
101
102
from mpl_toolkits.basemap import Basemap
from matplotlib import rcParams
from matplotlib.ticker import MultipleLocator
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab
# read in data on lat/lon grid.
hgt = mlab.load('500hgtdata.gz')
lons = mlab.load('500hgtlons.gz')
lats = mlab.load('500hgtlats.gz')
lons, lats = np.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=plt.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=plt.cm.Spectral)
# colorbar on bottom.
pos = ax.get_position()
l, b, w, h = pos.bounds
cax = plt.axes([l, b-0.05, w, 0.025]) # setup colorbar axes
plt.colorbar(cax=cax, orientation='horizontal',ticks=CS.levels[0::4]) # draw colorbar
plt.axes(ax) # make the original axes current again
mnh.drawcoastlines(linewidth=0.5)
delat = 30.
circles = np.arange(0.,90.,delat).tolist()+\
np.arange(-delat,-90,-delat).tolist()
mnh.drawparallels(circles,labels=[1,0,0,0])
delon = 45.
meridians = np.arange(0,360,delon)
mnh.drawmeridians(meridians,labels=[1,0,0,1])
plt.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=plt.cm.Spectral)
# colorbar on bottom.
pos = ax.get_position()
l, b, w, h = pos.bounds
cax = plt.axes([l, b-0.05, w, 0.025]) # setup colorbar axes
plt.colorbar(cax=cax,orientation='horizontal',ticks=MultipleLocator(320)) # draw colorbar
plt.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])
plt.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 = plt.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=plt.cm.RdBu)
# colorbar on right
pos = ax.get_position()
l, b, w, h = pos.bounds
cax = plt.axes([l+w+0.025, b, 0.025, h]) # setup colorbar axes
plt.colorbar(cax=cax, ticks=MultipleLocator(160), format='%4i') # draw colorbar
plt.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])
plt.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=plt.cm.RdBu)
# colorbar on right.
pos = ax.get_position()
l, b, w, h = pos.bounds
cax = plt.axes([l+w+0.025, b, 0.025, h]) # setup colorbar axes
plt.colorbar(cax=cax, ticks=MultipleLocator(160), format='%4i') # draw colorbar
plt.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])
plt.title('SH 500 hPa Height (cm.RdBu)')
plt.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.