Menu

[r1327]: / trunk / toolkits / basemap / examples / contour_demo.py  Maximize  Restore  History

Download this file

129 lines (113 with data), 4.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
from matplotlib.toolkits.basemap import Basemap, shiftgrid
from pylab import *
import cPickle, sys
from matplotlib.numerix import ma
# examples of filled contour plots on map projections.
# read in data on lat/lon grid.
datadict = cPickle.load(open('500hgt.pickle','rb'))
hgt = datadict['data']; lons = datadict['lons']; lats = datadict['lats']
# 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)
# setup of mollweide basemap
m = Basemap(resolution='c',area_thresh=10000.,projection='moll',lon_0=0)
x,y = m(lons,lats)
# make for points over projection horizon.
mask = logical_or(greater(x,1.e20),greater(y,1.e20))
xsize = rcParams['figure.figsize'][0]
fig=figure(figsize=(xsize,m.aspect*xsize))
ax = fig.add_axes([0.1,0.1,0.7,0.7],frameon=False)
# make a filled contour plot.
levels, colls = m.contour(x,y,hgt,15,linewidths=0.5,colors='k',badmask=mask)
levels, colls = m.contourf(x,y,hgt,15,cmap=cm.jet,colors=None,badmask=mask)
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()
m.drawmapboundary()
#m.fillcontinents()
# draw parallels and meridians.
parallels = arange(-90.,100,30.)
m.drawparallels(parallels)
meridians = arange(-360.,360.,30.)
m.drawmeridians(meridians)
title('Mollweide Filled Contour Demo')
show()
# set up Robinson map projection.
m = Basemap(resolution='c',area_thresh=10000.,projection='robin',lon_0=0)
# compute x,y of lat/lon grid.
x, y = m(lons, lats)
# make for points over projection horizon.
mask = logical_or(greater(x,1.e20),greater(y,1.e20))
fig=figure(figsize=(xsize,m.aspect*xsize))
ax = fig.add_axes([0.1,0.1,0.7,0.7],frameon=False)
# make a filled contour plot.
levels, colls = m.contour(x,y,hgt,15,linewidths=0.5,colors='k',badmask=mask)
levels, colls = m.contourf(x,y,hgt,15,cmap=cm.jet,colors=None,badmask=mask)
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()
m.drawmapboundary()
#m.fillcontinents()
# draw parallels and meridians.
parallels = arange(-90.,100,30.)
m.drawparallels(parallels)
meridians = arange(-360.,360.,30.)
m.drawmeridians(meridians)
title('Robinson Filled Contour Demo')
show()
# set up map projection (azimuthal equidistant).
m = Basemap(llcrnrlon=-135.,llcrnrlat=-20.,urcrnrlon=45.,urcrnrlat=-20.,
resolution='c',area_thresh=10000.,projection='aeqd',
lat_0=90.,lon_0=-90.)
# compute x,y of lat/lon grid.
x, y = m(lons, lats)
# make for points over projection horizon.
mask = logical_or(greater(x,1.e20),greater(y,1.e20))
xsize = rcParams['figure.figsize'][0]
fig=figure(figsize=(xsize,m.aspect*xsize))
ax = fig.add_axes([0.1,0.1,0.7,0.7],frameon=False)
# make a filled contour plot.
levels, colls = m.contour(x,y,hgt,15,linewidths=0.5,colors='k',badmask=mask)
levels, colls = m.contourf(x,y,hgt,15,cmap=cm.jet,colors=None,badmask=mask)
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()
m.drawmapboundary()
# draw parallels and meridians.
parallels = arange(0.,80,20.)
m.drawparallels(parallels,labels=[0,0,1,1])
meridians = arange(10.,360.,20.)
m.drawmeridians(meridians,labels=[1,1,1,1])
title('Azimuthal Equidistant Filled Contour Demo',y=1.075)
show()
# setup of orthographic basemap
m = Basemap(resolution='c',area_thresh=10000.,projection='ortho',\
lat_0=50.,lon_0=-120.)
x,y = m(lons,lats)
# make for points over projection horizon.
mask = logical_or(greater(x,1.e20),greater(y,1.e20))
xsize = rcParams['figure.figsize'][0]
fig=figure(figsize=(xsize,m.aspect*xsize))
ax = fig.add_axes([0.1,0.1,0.7,0.7],frameon=False)
# make a filled contour plot.
levels, colls = m.contour(x,y,hgt,15,linewidths=0.5,colors='k',badmask=mask)
levels, colls = m.contourf(x,y,hgt,15,cmap=cm.jet,colors=None,badmask=mask)
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()
m.drawmapboundary()
# draw parallels and meridians.
parallels = arange(0.,80,20.)
m.drawparallels(parallels)
meridians = arange(0.,360.,20.)
m.drawmeridians(meridians)
title('Orthographic Filled Contour Demo')
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.