コード例 #1
0
# make plots of etopo bathymetry/topography data on
# various map projections, drawing coastlines, state and
# country boundaries, filling continents and drawing
# parallels/meridians

from matplotlib.toolkits.basemap import Basemap, shiftgrid
from pylab import *
import cPickle

# read in topo data from pickle (on a regular lat/lon grid)
# longitudes go from 20 to 380.
topodict = cPickle.load(open('etopo20.pickle','rb'))
topoin = topodict['data']; lons = topodict['lons']; lats = topodict['lats']

# shift data so lons go from -180 to 180 instead of 20 to 380.
topoin,lons = shiftgrid(180.,topoin,lons,start=False)

print 'min/max etopo20 data:'
print min(ravel(topoin)),max(ravel(topoin))

# setup cylindrical equidistant map projection (global domain).
m = Basemap(-180.,-90,180.,90.,\
            resolution='c',area_thresh=10000.,projection='cyl')
# setup 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.75,0.75])
# plot image over map.
im = m.imshow(topoin,cm.jet)
cax = axes([0.875, 0.1, 0.05, 0.75]) # setup colorbar axes.
colorbar(tickfmt='%d', cax=cax) # draw colorbar
コード例 #2
0
from matplotlib.toolkits.basemap import Basemap, shiftgrid
from pylab import load, show, colorbar, axes, gca,\
                  figure, title, meshgrid, cm, arange

# examples of filled contour plots on map projections.

# read in data on lat/lon grid.
hgt = load('500hgtdata.gz')
lons = load('500hgtlons.gz')
lats = load('500hgtlats.gz')
# 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)

# create new figure
fig=figure()
# setup of sinusoidal basemap
m = Basemap(resolution='c',projection='sinu',lon_0=0)
ax = fig.add_axes([0.1,0.1,0.7,0.7])
# make a filled contour plot.
x, y = m(lons, lats)
CS = m.contour(x,y,hgt,15,linewidths=0.5,colors='k')
CS = m.contourf(x,y,hgt,15,cmap=cm.jet)
l,b,w,h=ax.get_position()
cax = axes([l+w+0.075, b, 0.05, h]) # setup colorbar axes
colorbar(drawedges=True, cax=cax) # draw colorbar
axes(ax)  # make the original axes current again
# draw coastlines and political boundaries.
m.drawcoastlines()
m.drawmapboundary()
m.fillcontinents()
コード例 #3
0
# country boundaries, filling continents and drawing
# parallels/meridians

from matplotlib.toolkits.basemap import Basemap, shiftgrid
from pylab import *
import cPickle

# read in topo data from pickle (on a regular lat/lon grid)
# longitudes go from 20 to 380.
topodict = cPickle.load(open('etopo20.pickle', 'rb'))
topoin = topodict['data']
lons = topodict['lons']
lats = topodict['lats']

# shift data so lons go from -180 to 180 instead of 20 to 380.
topoin, lons = shiftgrid(180., topoin, lons, start=False)

print 'min/max etopo20 data:'
print min(ravel(topoin)), max(ravel(topoin))

# setup cylindrical equidistant map projection (global domain).
m = Basemap(-180.,-90,180.,90.,\
            resolution='c',area_thresh=10000.,projection='cyl')
# setup 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.75, 0.75])
# plot image over map.
im = m.imshow(topoin, cm.jet)
cax = axes([0.875, 0.1, 0.05, 0.75])  # setup colorbar axes.
colorbar(tickfmt='%d', cax=cax)  # draw colorbar
コード例 #4
0
ファイル: draw_maps_pyth-exp2.py プロジェクト: bslew/cpems
from pylab import *

#mapfile = '/home/blew/programy/Mscs/WMAPstuff/SKregstat/sm1.0/3sigma_chisq_comb-K.lonlatT'
#lonfile = '/home/blew/programy/Mscs/WMAPstuff/SKregstat/sm1.0/3sigma_chisq_comb-K.lon'
#latfile = '/home/blew/programy/Mscs/WMAPstuff/SKregstat/sm1.0/3sigma_chisq_comb-K.lat'

mapfile = sys.argv[1]+'.lonlatT'
lonfile = sys.argv[1]+'.lon'
latfile = sys.argv[1]+'.lat'
color_num = int(sys.argv[2])

# load data
map=array(load(mapfile))
lons=array(load(lonfile))
lats=array(load(latfile))
map,lons = shiftgrid(180.,map,lons,start=False)

# Mollweide projection
m1 = Basemap(projection='moll',lon_0=0.5*(lons[0]+lons[-1]))
lons, lats = meshgrid(lons, lats)
fig1 = m1.createfigure()
x, y = m1(lons, lats)
cs = m1.contourf(x,y,map,color_num,cmap=cm.jet)
m1.drawparallels(arange(-90.,90.,20.),labels=[1,0,0,0])
m1.drawmeridians(arange(0.,420.,30.),labels=[0,0,0,1])
#title('Moll. proj:'+ sys.argv[1])
title(r'$>3\sigma\/ detections\/ composite\/ map:\/ skewness$')
#title(r'$>3\sigma\/ detections\/ composite\/ map:\/ kurtosis$')
colorbar();

savefig(sys.argv[1]+'-moll.png'); #savefig(sys.argv[1]+'-moll.eps')
コード例 #5
0
nframe = 0; n1 = 10
l,b,w,h=ax.get_position()
# loop over times, make contour plots, draw coastlines, 
# parallels, meridians and title.
for nt,date in enumerate(datelabels[1:]):
    CS = m.contour(x,y,slp[nt,:,:],clevs,linewidths=0.5,colors='k',animated=True)
    CS = m.contourf(x,y,slp[nt,:,:],clevs,cmap=p.cm.RdBu_r,animated=True)
    # plot wind vectors on lat/lon grid.
    # rotate wind vectors to map projection coordinates.
    #urot,vrot = m.rotate_vector(u[nt,:,:],v[nt,:,:],lons,lats)
    # plot wind vectors over map.
    #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
コード例 #6
0
                animated=True)
 CS = m.contourf(x,
                 y,
                 slp[nt, :, :],
                 clevs,
                 cmap=p.cm.RdBu_r,
                 animated=True)
 # plot wind vectors on lat/lon grid.
 # rotate wind vectors to map projection coordinates.
 #urot,vrot = m.rotate_vector(u[nt,:,:],v[nt,:,:],lons,lats)
 # plot wind vectors over map.
 #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.
コード例 #7
0
from matplotlib.toolkits.basemap import Basemap, shiftgrid
from pylab import *

# examples of filled contour plots on map projections.

# read in data on lat/lon grid.
hgt = load('500hgtdata.gz')
lons = load('500hgtlons.gz')
lats = load('500hgtlats.gz')
# 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 sinusoidal basemap
m = Basemap(resolution='c', projection='sinu', lon_0=0)
fig = figure()
ax = fig.add_axes([0.1, 0.1, 0.7, 0.7])
# make a filled contour plot.
x, y = m(lons, lats)
CS = m.contour(x, y, hgt, 15, linewidths=0.5, colors='k')
CS = m.contourf(x, y, hgt, 15, cmap=cm.jet)
l, b, w, h = ax.get_position()
cax = axes([l + w + 0.075, b, 0.05, h])  # setup colorbar axes
colorbar(drawedges=True, 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(-60., 90, 30.)
コード例 #8
0
ファイル: test.py プロジェクト: jtomase/matplotlib
# make plots of etopo bathymetry/topography data on
# various map projections, drawing coastlines, state and
# country boundaries, filling continents and drawing
# parallels/meridians

from matplotlib.toolkits.basemap import Basemap, shiftgrid
from pylab import *

# read in topo data (on a regular lat/lon grid)
# longitudes go from 20 to 380.
topodatin = array(load('etopo20data.gz'),'d')
lonsin = array(load('etopo20lons.gz'),'d')
latsin = array(load('etopo20lats.gz'),'d')

# shift data so lons go from -180 to 180 instead of 20 to 380.
topoin,lons = shiftgrid(180.,topodatin,lonsin,start=False)
lats = latsin

print 'min/max etopo20 data:'
print min(ravel(topoin)),max(ravel(topoin))

# setup cylindrical equidistant map projection (global domain).
m = Basemap(llcrnrlon=-180.,llcrnrlat=-90,urcrnrlon=180.,urcrnrlat=90.,\
            resolution='c',area_thresh=10000.,projection='cyl')
# setup figure with same aspect ratio as map.
fig=m.createfigure()
ax = fig.add_axes([0.1,0.1,0.75,0.75])
# plot image over map.
im = m.imshow(topoin,cm.jet)
cax = axes([0.875, 0.1, 0.05, 0.75]) # setup colorbar axes.
colorbar(tickfmt='%d', cax=cax) # draw colorbar