|
From: <js...@us...> - 2008-05-16 19:20:16
|
Revision: 5150
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5150&view=rev
Author: jswhit
Date: 2008-05-16 12:20:04 -0700 (Fri, 16 May 2008)
Log Message:
-----------
convert to numpy and pyplt namespaces.
Modified Paths:
--------------
trunk/toolkits/basemap/examples/test.py
Modified: trunk/toolkits/basemap/examples/test.py
===================================================================
--- trunk/toolkits/basemap/examples/test.py 2008-05-16 17:47:51 UTC (rev 5149)
+++ trunk/toolkits/basemap/examples/test.py 2008-05-16 19:20:04 UTC (rev 5150)
@@ -4,56 +4,57 @@
# parallels/meridians
from mpl_toolkits.basemap import Basemap, shiftgrid
-from pylab import show,arange,draw,figure,load,ravel,cm,axes,\
- colorbar,title,gca,pi,meshgrid
+import numpy as np
+import matplotlib.pyplot as plt
+import matplotlib.mlab as mlab
import matplotlib.colors as colors
# read in topo data (on a regular lat/lon grid)
# longitudes go from 20 to 380.
-topodatin = load('etopo20data.gz')
-lonsin = load('etopo20lons.gz')
-latsin = load('etopo20lats.gz')
+topodatin = mlab.load('etopo20data.gz')
+lonsin = mlab.load('etopo20lons.gz')
+latsin = mlab.load('etopo20lats.gz')
# 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))
+print topoin.min(),topoin.max()
# create new figure
-fig=figure()
+fig=plt.figure()
# setup cylindrical equidistant map projection (global domain).
m = Basemap(llcrnrlon=-180.,llcrnrlat=-90,urcrnrlon=180.,urcrnrlat=90.,\
resolution='c',area_thresh=10000.,projection='cyl')
ax = fig.add_axes([0.1,0.1,0.7,0.7])
# plot image over map.
-im = m.imshow(topoin,cm.jet)
+im = m.imshow(topoin,plt.cm.jet)
# get axes position, add colorbar axes to right of this.
pos = ax.get_position()
l, b, w, h = pos.bounds
-cax = axes([l+w+0.05, b, 0.05, h]) # setup colorbar axes.
-colorbar(cax=cax) # draw colorbar
-axes(ax) # make the original axes current again
+cax = plt.axes([l+w+0.05, b, 0.05, h]) # setup colorbar axes.
+plt.colorbar(cax=cax) # draw colorbar
+plt.axes(ax) # make the original axes current again
m.drawcoastlines()
#m.drawcountries()
#m.drawstates()
#m.fillcontinents()
# draw parallels
delat = 30.
-circles = arange(0.,90.+delat,delat).tolist()+\
- arange(-delat,-90.-delat,-delat).tolist()
+circles = np.arange(0.,90.+delat,delat).tolist()+\
+ np.arange(-delat,-90.-delat,-delat).tolist()
m.drawparallels(circles,labels=[1,0,0,1])
# draw meridians
delon = 60.
-meridians = arange(-180,180,delon)
+meridians = np.arange(-180,180,delon)
m.drawmeridians(meridians,labels=[1,0,0,1])
-title('Cylindrical Equidistant')
+plt.title('Cylindrical Equidistant')
print 'plotting Cylindrical Equidistant example ...'
print m.srs
# create new figure
-fig=figure()
+fig=plt.figure()
# setup miller cylindrical map projection.
m = Basemap(llcrnrlon=-180.,llcrnrlat=-90,urcrnrlon=180.,urcrnrlat=90.,\
resolution='c',area_thresh=10000.,projection='mill')
@@ -62,18 +63,18 @@
topodat = m.transform_scalar(topoin,lons,lats,nx,ny)
fig.add_axes([0.1,0.1,0.75,0.75])
# plot image over map.
-im = m.imshow(topodat,cm.jet)
+im = m.imshow(topodat,plt.cm.jet)
m.drawcoastlines()
# draw parallels
m.drawparallels(circles,labels=[1,1,1,1])
# draw meridians
m.drawmeridians(meridians,labels=[1,1,1,1])
-title('Miller Cylindrical',y=1.1)
+plt.title('Miller Cylindrical',y=1.1)
print 'plotting Miller Cylindrical example ...'
print m.srs
# create new figure
-fig=figure()
+fig=plt.figure()
# setup mercator map projection (-80 to +80).
m = Basemap(llcrnrlon=-180.,llcrnrlat=-80,urcrnrlon=180.,urcrnrlat=80.,\
resolution='c',area_thresh=10000.,projection='merc',\
@@ -83,7 +84,7 @@
topodat = m.transform_scalar(topoin,lons,lats,nx,ny)
fig.add_axes([0.1,0.1,0.75,0.75])
# plot image over map.
-im = m.imshow(topodat,cm.jet)
+im = m.imshow(topodat,plt.cm.jet)
m.drawcoastlines()
m.drawcountries()
m.drawstates()
@@ -92,12 +93,12 @@
m.drawparallels(circles,labels=[1,1,1,1])
# draw meridians
m.drawmeridians(meridians,labels=[1,1,1,1])
-title('Mercator',y=1.1)
+plt.title('Mercator',y=1.1)
print 'plotting Mercator example ...'
print m.srs
# create new figure
-fig=figure()
+fig=plt.figure()
# setup cassini-soldner basemap.
m = Basemap(llcrnrlon=-6,llcrnrlat=49,urcrnrlon=4,urcrnrlat=59,\
resolution='l',area_thresh=1000.,projection='cass',\
@@ -107,29 +108,29 @@
nx = int((m.xmax-m.xmin)/20000.)+1; ny = int((m.ymax-m.ymin)/20000.)+1
topodat = m.transform_scalar(topoin,lons,lats,nx,ny)
# plot image over map.
-im = m.imshow(topodat,cm.jet)
+im = m.imshow(topodat,plt.cm.jet)
# get current axis instance.
-ax = gca()
+ax = plt.gca()
pos = ax.get_position()
l, b, w, h = pos.bounds
-cax = axes([l+w+0.05, b, 0.05, h]) # setup colorbar axes.
-colorbar(cax=cax) # draw colorbar
-axes(ax) # make the original axes current again
+cax = plt.axes([l+w+0.05, b, 0.05, h]) # setup colorbar axes.
+plt.colorbar(cax=cax) # draw colorbar
+plt.axes(ax) # make the original axes current again
m.drawcoastlines()
# draw parallels
delat = 2.
-circles = arange(40.,70.,delat)
+circles = np.arange(40.,70.,delat)
m.drawparallels(circles,labels=[1,0,0,1],fontsize=10)
# draw meridians
delon = 2.
-meridians = arange(-10,10,delon)
+meridians = np.arange(-10,10,delon)
m.drawmeridians(meridians,labels=[1,0,0,1],fontsize=10)
-title('Cassini-Soldner Projection')
+plt.title('Cassini-Soldner Projection')
print 'plotting Cassini-Soldner example ...'
print m.srs
# create new figure
-fig=figure()
+fig=plt.figure()
# setup gnomonic basemap.
m = Basemap(llcrnrlon=-95.,llcrnrlat=-52,urcrnrlon=-35.,urcrnrlat=15.,\
resolution='c',area_thresh=10000.,projection='gnom',\
@@ -139,30 +140,30 @@
nx = int((m.xmax-m.xmin)/40000.)+1; ny = int((m.ymax-m.ymin)/40000.)+1
topodat = m.transform_scalar(topoin,lons,lats,nx,ny)
# plot image over map.
-im = m.imshow(topodat,cm.jet)
+im = m.imshow(topodat,plt.cm.jet)
# get current axis instance.
-ax = gca()
+ax = plt.gca()
pos = ax.get_position()
l, b, w, h = pos.bounds
-cax = axes([l+w+0.05, b, 0.05, h]) # setup colorbar axes.
-colorbar(cax=cax) # draw colorbar
-axes(ax) # make the original axes current again
+cax = plt.axes([l+w+0.05, b, 0.05, h]) # setup colorbar axes.
+plt.colorbar(cax=cax) # draw colorbar
+plt.axes(ax) # make the original axes current again
m.drawcoastlines()
m.drawcountries()
# draw parallels
delat = 20.
-circles = arange(-80.,100.,delat)
+circles = np.arange(-80.,100.,delat)
m.drawparallels(circles,labels=[1,0,0,1],fontsize=10)
# draw meridians
delon = 20.
-meridians = arange(-180,180,delon)
+meridians = np.arange(-180,180,delon)
m.drawmeridians(meridians,labels=[1,0,0,1],fontsize=10)
-title('Gnomonic Projection')
+plt.title('Gnomonic Projection')
print 'plotting Gnomonic example ...'
print m.srs
# create new figure
-fig=figure()
+fig=plt.figure()
# setup transverse mercator basemap.
m = Basemap(width=2*6370997,height=3.1*6370997,\
resolution='c',area_thresh=10000.,projection='cass',\
@@ -172,29 +173,29 @@
nx = int((m.xmax-m.xmin)/40000.)+1; ny = int((m.ymax-m.ymin)/40000.)+1
topodat = m.transform_scalar(topoin,lons,lats,nx,ny)
# plot image over map.
-im = m.imshow(topodat,cm.jet)
+im = m.imshow(topodat,plt.cm.jet)
# get current axis instance.
-ax = gca()
+ax = plt.gca()
pos = ax.get_position()
l, b, w, h = pos.bounds
-cax = axes([l+w+0.05, b, 0.05, h]) # setup colorbar axes.
-colorbar(cax=cax) # draw colorbar
-axes(ax) # make the original axes current again
+cax = plt.axes([l+w+0.05, b, 0.05, h]) # setup colorbar axes.
+plt.colorbar(cax=cax) # draw colorbar
+plt.axes(ax) # make the original axes current again
m.drawcoastlines()
# draw parallels
delat = 20.
-circles = arange(-80.,100.,delat)
+circles = np.arange(-80.,100.,delat)
m.drawparallels(circles,labels=[1,0,0,0],fontsize=10)
# draw meridians
delon = 20.
-meridians = arange(-180,180,delon)
+meridians = np.arange(-180,180,delon)
m.drawmeridians(meridians,labels=[1,0,0,0],fontsize=10)
-title('Transverse Mercator Projection')
+plt.title('Transverse Mercator Projection')
print 'plotting Transverse Mercator example ...'
print m.srs
# create new figure
-fig=figure()
+fig=plt.figure()
# setup oblique mercator basemap.
m = Basemap(height=16700000,width=12000000,
resolution='l',area_thresh=1000.,projection='omerc',\
@@ -203,27 +204,27 @@
nx = int((m.xmax-m.xmin)/20000.)+1; ny = int((m.ymax-m.ymin)/20000.)+1
topodat = m.transform_scalar(topoin,lons,lats,nx,ny)
# plot image over map.
-im = m.imshow(topodat,cm.jet)
+im = m.imshow(topodat,plt.cm.jet)
# get current axis instance.
-ax = gca()
+ax = plt.gca()
pos = ax.get_position()
l, b, w, h = pos.bounds
-cax = axes([l+w+0.05, b, 0.05, h]) # setup colorbar axes.
-colorbar(cax=cax) # draw colorbar
-axes(ax) # make the original axes current again
+cax = plt.axes([l+w+0.05, b, 0.05, h]) # setup colorbar axes.
+plt.colorbar(cax=cax) # draw colorbar
+plt.axes(ax) # make the original axes current again
m.drawcoastlines()
m.drawcountries()
m.drawstates()
# draw parallels
-m.drawparallels(arange(-80,81,20),labels=[1,0,0,0],fontsize=10)
+m.drawparallels(np.arange(-80,81,20),labels=[1,0,0,0],fontsize=10)
# draw meridians
-m.drawmeridians(arange(-180,181,30),labels=[0,0,0,1],fontsize=10)
-title('Oblique Mercator Projection')
+m.drawmeridians(np.arange(-180,181,30),labels=[0,0,0,1],fontsize=10)
+plt.title('Oblique Mercator Projection')
print 'plotting Oblique Mercator example ...'
print m.srs
# create new figure
-fig=figure()
+fig=plt.figure()
# setup polyconic basemap.
m = Basemap(llcrnrlon=-35.,llcrnrlat=-30,urcrnrlon=80.,urcrnrlat=50.,\
resolution='c',area_thresh=1000.,projection='poly',\
@@ -233,30 +234,30 @@
nx = int((m.xmax-m.xmin)/40000.)+1; ny = int((m.ymax-m.ymin)/40000.)+1
topodat = m.transform_scalar(topoin,lons,lats,nx,ny)
# plot image over map.
-im = m.imshow(topodat,cm.jet)
+im = m.imshow(topodat,plt.cm.jet)
# get current axis instance.
-ax = gca()
+ax = plt.gca()
pos = ax.get_position()
l, b, w, h = pos.bounds
-cax = axes([l+w+0.05, b, 0.05, h]) # setup colorbar axes.
-colorbar(cax=cax) # draw colorbar
-axes(ax) # make the original axes current again
+cax = plt.axes([l+w+0.05, b, 0.05, h]) # setup colorbar axes.
+plt.colorbar(cax=cax) # draw colorbar
+plt.axes(ax) # make the original axes current again
m.drawcoastlines()
m.drawcountries()
# draw parallels
delat = 20.
-circles = arange(-80.,100.,delat)
+circles = np.arange(-80.,100.,delat)
m.drawparallels(circles,labels=[1,0,0,0],fontsize=10)
# draw meridians
delon = 20.
-meridians = arange(-180,180,delon)
+meridians = np.arange(-180,180,delon)
m.drawmeridians(meridians,labels=[1,0,0,1],fontsize=10)
-title('Polyconic Projection')
+plt.title('Polyconic Projection')
print 'plotting Polyconic example ...'
print m.srs
# create new figure
-fig=figure()
+fig=plt.figure()
# setup equidistant conic
m = Basemap(llcrnrlon=-90.,llcrnrlat=18,urcrnrlon=-70.,urcrnrlat=26.,\
resolution='l',area_thresh=1000.,projection='eqdc',\
@@ -266,30 +267,30 @@
topodat = m.transform_scalar(topoin,lons,lats,nx,ny)
ax = fig.add_axes([0.1,0.1,0.7,0.7])
# plot image over map.
-im = m.imshow(topodat,cm.jet)
+im = m.imshow(topodat,plt.cm.jet)
pos = ax.get_position()
l, b, w, h = pos.bounds
-cax = axes([l+w+0.05, b, 0.05, h]) # setup colorbar axes.
-colorbar(cax=cax) # draw colorbar
-axes(ax) # make the original axes current again
+cax = plt.axes([l+w+0.05, b, 0.05, h]) # setup colorbar axes.
+plt.colorbar(cax=cax) # draw colorbar
+plt.axes(ax) # make the original axes current again
m.drawcoastlines()
m.drawcountries()
m.drawstates()
m.fillcontinents(color='olive')
# draw parallels
delat = 2.
-circles = arange(17,27,delat)
+circles = np.arange(17,27,delat)
m.drawparallels(circles,labels=[1,0,0,0])
# draw meridians
delon = 5.
-meridians = arange(-100,-60,delon)
+meridians = np.arange(-100,-60,delon)
m.drawmeridians(meridians,labels=[0,0,0,1])
-title('Equidistant Conic')
+plt.title('Equidistant Conic')
print 'plotting Equidistant Conic example ...'
print m.srs
# create new figure
-fig=figure()
+fig=plt.figure()
# setup lambert conformal map projection (North America).
m = Basemap(llcrnrlon=-145.5,llcrnrlat=1,urcrnrlon=-2.566,urcrnrlat=46.352,\
resolution='c',area_thresh=10000.,projection='lcc',\
@@ -299,31 +300,31 @@
topodat = m.transform_scalar(topoin,lons,lats,nx,ny)
ax = fig.add_axes([0.1,0.1,0.7,0.7])
# plot image over map.
-im = m.imshow(topodat,cm.jet)
+im = m.imshow(topodat,plt.cm.jet)
pos = ax.get_position()
l, b, w, h = pos.bounds
-cax = axes([l+w+0.075, b, 0.05, h]) # setup colorbar axes.
-colorbar(cax=cax) # draw colorbar
-axes(ax) # make the original axes current again
+cax = plt.axes([l+w+0.075, b, 0.05, h]) # setup colorbar axes.
+plt.colorbar(cax=cax) # draw colorbar
+plt.axes(ax) # make the original axes current again
m.drawcoastlines()
m.drawcountries()
m.drawstates()
#m.fillcontinents()
# draw parallels
delat = 20.
-circles = arange(0.,90.+delat,delat).tolist()+\
- arange(-delat,-90.-delat,-delat).tolist()
+circles = np.arange(0.,90.+delat,delat).tolist()+\
+ np.arange(-delat,-90.-delat,-delat).tolist()
m.drawparallels(circles,labels=[1,1,0,1])
# draw meridians
delon = 30.
-meridians = arange(10.,360.,delon)
+meridians = np.arange(10.,360.,delon)
m.drawmeridians(meridians,labels=[1,1,0,1])
-title('Lambert Conformal Conic')
+plt.title('Lambert Conformal Conic')
print 'plotting Lambert Conformal example ...'
print m.srs
# create new figure
-fig=figure()
+fig=plt.figure()
# setup albers equal area map projection (Europe).
m = Basemap(llcrnrlon=-10.,llcrnrlat=20,urcrnrlon=55.,urcrnrlat=75,\
resolution='l',projection='aea',\
@@ -333,30 +334,30 @@
topodat = m.transform_scalar(topoin,lons,lats,nx,ny)
ax = fig.add_axes([0.1,0.1,0.7,0.7])
# plot image over map.
-im = m.imshow(topodat,cm.jet)
+im = m.imshow(topodat,plt.cm.jet)
im.set_clim(-4000.,3000.) # adjust range of colors.
pos = ax.get_position()
l, b, w, h = pos.bounds
-cax = axes([l+w+0.075, b, 0.05, h]) # setup colorbar axes.
-colorbar(cax=cax) # draw colorbar
-axes(ax) # make the original axes current again
+cax = plt.axes([l+w+0.075, b, 0.05, h]) # setup colorbar axes.
+plt.colorbar(cax=cax) # draw colorbar
+plt.axes(ax) # make the original axes current again
m.drawcoastlines()
m.drawcountries()
# draw parallels
delat = 20.
-circles = arange(0.,90.+delat,delat).tolist()+\
- arange(-delat,-90.-delat,-delat).tolist()
+circles = np.arange(0.,90.+delat,delat).tolist()+\
+ np.arange(-delat,-90.-delat,-delat).tolist()
m.drawparallels(circles,labels=[1,1,1,1])
# draw meridians
delon = 30.
-meridians = arange(10.,360.,delon)
+meridians = np.arange(10.,360.,delon)
m.drawmeridians(meridians,labels=[1,1,1,1])
-title('Albers Equal Area Conic',y=1.075)
+plt.title('Albers Equal Area Conic',y=1.075)
print 'plotting Albers Equal Area example ...'
print m.srs
# create new figure
-fig=figure()
+fig=plt.figure()
# setup stereographic map projection (Southern Hemisphere).
#m = Basemap(llcrnrlon=120.,llcrnrlat=0.,urcrnrlon=-60.,urcrnrlat=0.,\
# resolution='c',area_thresh=10000.,projection='stere',\
@@ -369,12 +370,12 @@
topodat = m.transform_scalar(topoin,lons,lats,nx,ny)
ax = fig.add_axes([0.1,0.1,0.7,0.7])
# plot image over map.
-im = m.imshow(topodat,cm.jet)
+im = m.imshow(topodat,plt.cm.jet)
pos = ax.get_position()
l, b, w, h = pos.bounds
-cax = axes([l+w+0.075, b, 0.05, h]) # setup colorbar axes.
-colorbar(cax=cax) # draw colorbar
-axes(ax) # make the original axes current again
+cax = plt.axes([l+w+0.075, b, 0.05, h]) # setup colorbar axes.
+plt.colorbar(cax=cax) # draw colorbar
+plt.axes(ax) # make the original axes current again
m.drawcoastlines()
m.drawcountries()
#m.fillcontinents()
@@ -382,12 +383,12 @@
m.drawparallels(circles)
# draw meridians
m.drawmeridians(meridians,labels=[1,1,1,1])
-title('Polar Stereographic',y=1.075)
+plt.title('Polar Stereographic',y=1.075)
print 'plotting Stereographic example ...'
print m.srs
# create new figure
-fig=figure()
+fig=plt.figure()
# setup lambert azimuthal map projection (Northern Hemisphere).
#m = Basemap(llcrnrlon=-150.,llcrnrlat=-18.,urcrnrlon=30.,urcrnrlat=--18.,\
# resolution='c',area_thresh=10000.,projection='laea',\
@@ -400,12 +401,12 @@
topodat = m.transform_scalar(topoin,lons,lats,nx,ny)
ax = fig.add_axes([0.1,0.1,0.7,0.7])
# plot image over map.
-im = m.imshow(topodat,cm.jet)
+im = m.imshow(topodat,plt.cm.jet)
pos = ax.get_position()
l, b, w, h = pos.bounds
-cax = axes([l+w+0.075, b, 0.05, h]) # setup colorbar axes.
-colorbar(cax=cax) # draw colorbar
-axes(ax) # make the original axes current again
+cax = plt.axes([l+w+0.075, b, 0.05, h]) # setup colorbar axes.
+plt.colorbar(cax=cax) # draw colorbar
+plt.axes(ax) # make the original axes current again
m.drawcoastlines()
m.drawcountries()
m.drawstates()
@@ -414,12 +415,12 @@
m.drawparallels(circles)
# draw meridians
m.drawmeridians(meridians,labels=[1,1,1,1])
-title('Lambert Azimuthal Equal Area',y=1.075)
+plt.title('Lambert Azimuthal Equal Area',y=1.075)
print 'plotting Lambert Azimuthal example ...'
print m.srs
# create new figure
-fig=figure()
+fig=plt.figure()
# setup azimuthal equidistant map projection (Northern Hemisphere).
#m = Basemap(llcrnrlon=-150.,llcrnrlat=40.,urcrnrlon=30.,urcrnrlat=40.,\
# resolution='c',area_thresh=10000.,projection='aeqd',\
@@ -432,12 +433,12 @@
topodat = m.transform_scalar(topoin,lons,lats,nx,ny)
ax = fig.add_axes([0.1,0.1,0.7,0.7])
# plot image over map.
-im = m.imshow(topodat,cm.jet)
+im = m.imshow(topodat,plt.cm.jet)
pos = ax.get_position()
l, b, w, h = pos.bounds
-cax = axes([l+w+0.075, b, 0.05, h]) # setup colorbar axes.
-colorbar(cax=cax) # draw colorbar
-axes(ax) # make the original axes current again
+cax = plt.axes([l+w+0.075, b, 0.05, h]) # setup colorbar axes.
+plt.colorbar(cax=cax) # draw colorbar
+plt.axes(ax) # make the original axes current again
m.drawcoastlines()
m.drawcountries()
m.drawstates()
@@ -446,7 +447,7 @@
m.drawparallels(circles)
# draw meridians
m.drawmeridians(meridians,labels=[1,1,1,1])
-title('Azimuthal Equidistant',y=1.075)
+plt.title('Azimuthal Equidistant',y=1.075)
print 'plotting Azimuthal Equidistant example ...'
print m.srs
@@ -454,20 +455,20 @@
# mollweide and robinson)
# create new figure
-fig=figure()
+fig=plt.figure()
# setup of basemap ('ortho' = orthographic projection)
m = Basemap(projection='ortho',
resolution='c',area_thresh=10000.,lat_0=30,lon_0=-60)
# transform to nx x ny regularly spaced native projection grid
# nx and ny chosen to have roughly the same horizontal res as original image.
-dx = 2.*pi*m.rmajor/len(lons)
+dx = 2.*np.pi*m.rmajor/len(lons)
nx = int((m.xmax-m.xmin)/dx)+1; ny = int((m.ymax-m.ymin)/dx)+1
# interpolate to native projection grid.
# values outside of projection limb will be masked.
topo = m.transform_scalar(topoin,lons,lats,nx,ny,masked=True)
ax = fig.add_axes([0.1,0.1,0.7,0.7])
# set missing value in color pallette.
-palette = cm.jet
+palette = plt.cm.jet
palette.set_bad(ax.get_axis_bgcolor(), 0.0)
# plot image over map with imshow.
# (if contourf were used, no interpolation would be necessary
@@ -476,39 +477,39 @@
im = m.imshow(topo,palette,norm=colors.normalize(clip=False))
pos = ax.get_position()
l, b, w, h = pos.bounds
-cax = axes([l+w+0.075, b, 0.05, h]) # setup colorbar axes.
-colorbar(cax=cax) # draw colorbar
-axes(ax) # make the original axes current again
+cax = plt.axes([l+w+0.075, b, 0.05, h]) # setup colorbar axes.
+plt.colorbar(cax=cax) # draw colorbar
+plt.axes(ax) # make the original axes current again
# draw coastlines and political boundaries.
m.drawcoastlines()
# draw parallels and meridians (labelling is
# not implemented for orthographic).
-parallels = arange(-80.,90,20.)
+parallels = np.arange(-80.,90,20.)
m.drawparallels(parallels)
-meridians = arange(0.,360.,20.)
+meridians = np.arange(0.,360.,20.)
m.drawmeridians(meridians)
# draw boundary around map region.
m.drawmapboundary()
-title('Orthographic')
+plt.title('Orthographic')
print 'plotting Orthographic example ...'
print m.srs
# create new figure
-fig=figure()
+fig=plt.figure()
# setup of basemap ('geos' = geostationary projection)
m = Basemap(projection='geos',
rsphere=(6378137.00,6356752.3142),\
resolution='c',area_thresh=10000.,lon_0=0,satellite_height=35785831)
# transform to nx x ny regularly spaced native projection grid
# nx and ny chosen to have roughly the same horizontal res as original image.
-dx = 2.*pi*m.rmajor/len(lons)
+dx = 2.*np.pi*m.rmajor/len(lons)
nx = int((m.xmax-m.xmin)/dx)+1; ny = int((m.ymax-m.ymin)/dx)+1
# interpolate to native projection grid.
# values outside of projection limb will be masked.
topo = m.transform_scalar(topoin,lons,lats,nx,ny,masked=True)
ax = fig.add_axes([0.1,0.1,0.7,0.7])
# set missing value in color pallette.
-palette = cm.jet
+palette = plt.cm.jet
palette.set_bad(ax.get_axis_bgcolor(), 0.0)
# plot image over map with imshow.
# (if contourf were used, no interpolation would be necessary
@@ -517,104 +518,104 @@
im = m.imshow(topo,palette,norm=colors.normalize(clip=False))
pos = ax.get_position()
l, b, w, h = pos.bounds
-cax = axes([l+w+0.075, b, 0.05, h]) # setup colorbar axes.
-colorbar(cax=cax) # draw colorbar
-axes(ax) # make the original axes current again
+cax = plt.axes([l+w+0.075, b, 0.05, h]) # setup colorbar axes.
+plt.colorbar(cax=cax) # draw colorbar
+plt.axes(ax) # make the original axes current again
# draw coastlines and political boundaries.
m.drawcoastlines()
# draw parallels and meridians (labelling is
# not implemented for geostationary).
-parallels = arange(-80.,90,20.)
+parallels = np.arange(-80.,90,20.)
m.drawparallels(parallels)
-meridians = arange(0.,360.,20.)
+meridians = np.arange(0.,360.,20.)
m.drawmeridians(meridians)
# draw boundary around map region.
m.drawmapboundary()
-title('Geostationary')
+plt.title('Geostationary')
print 'plotting Geostationary example ...'
print m.srs
# create new figure
-fig=figure()
+fig=plt.figure()
# setup of sinusoidal ('sinu' = sinusioidal projection)
m = Basemap(projection='sinu',
resolution='c',area_thresh=10000.,lon_0=0.5*(lonsin[0]+lonsin[-1]))
ax = fig.add_axes([0.1,0.1,0.7,0.7])
# plot image over map with pcolormesh.
-x,y = m(*meshgrid(lonsin,latsin))
+x,y = m(*np.meshgrid(lonsin,latsin))
p = m.pcolormesh(x,y,topodatin,shading='flat')
pos = ax.get_position()
l, b, w, h = pos.bounds
-cax = axes([l+w+0.05, b, 0.05, h]) # setup colorbar axes.
-colorbar(cax=cax) # draw colorbar
-axes(ax) # make the original axes current again
+cax = plt.axes([l+w+0.05, b, 0.05, h]) # setup colorbar axes.
+plt.colorbar(cax=cax) # draw colorbar
+plt.axes(ax) # make the original axes current again
# draw coastlines and political boundaries.
m.drawcoastlines()
# draw parallels and meridians
-parallels = arange(-60.,90,30.)
+parallels = np.arange(-60.,90,30.)
m.drawparallels(parallels,labels=[1,0,0,0])
-meridians = arange(0.,360.,30.)
+meridians = np.arange(0.,360.,30.)
m.drawmeridians(meridians)
# draw boundary around map region.
m.drawmapboundary()
-title('Sinusoidal')
+plt.title('Sinusoidal')
print 'plotting Sinusoidal example ...'
print m.srs
# create new figure
-fig=figure()
+fig=plt.figure()
# setup of basemap ('moll' = mollweide projection)
m = Basemap(projection='moll',
resolution='c',area_thresh=10000.,lon_0=0.5*(lonsin[0]+lonsin[-1]))
ax = fig.add_axes([0.1,0.1,0.7,0.7])
# plot image over map with pcolormesh.
-x,y = m(*meshgrid(lonsin,latsin))
+x,y = m(*np.meshgrid(lonsin,latsin))
p = m.pcolormesh(x,y,topodatin,shading='flat')
pos = ax.get_position()
l, b, w, h = pos.bounds
-cax = axes([l+w+0.05, b, 0.05, h]) # setup colorbar axes.
-colorbar(cax=cax) # draw colorbar
-axes(ax) # make the original axes current again
+cax = plt.axes([l+w+0.05, b, 0.05, h]) # setup colorbar axes.
+plt.colorbar(cax=cax) # draw colorbar
+plt.axes(ax) # make the original axes current again
# draw coastlines and political boundaries.
m.drawcoastlines()
# draw parallels and meridians
-parallels = arange(-60.,90,30.)
+parallels = np.arange(-60.,90,30.)
m.drawparallels(parallels,labels=[1,0,0,0])
-meridians = arange(0.,360.,30.)
+meridians = np.arange(0.,360.,30.)
m.drawmeridians(meridians)
# draw boundary around map region.
m.drawmapboundary()
-title('Mollweide')
+plt.title('Mollweide')
print 'plotting Mollweide example ...'
print m.srs
# create new figure
-fig=figure()
+fig=plt.figure()
# setup of basemap ('robin' = robinson projection)
m = Basemap(projection='robin',
resolution='c',area_thresh=10000.,lon_0=0.5*(lonsin[0]+lonsin[-1]))
ax = fig.add_axes([0.1,0.1,0.7,0.7])
# plot image over map with pcolormesh.
-x,y = m(*meshgrid(lonsin,latsin))
+x,y = m(*np.meshgrid(lonsin,latsin))
p = m.pcolormesh(x,y,topodatin,shading='flat')
pos = ax.get_position()
l, b, w, h = pos.bounds
-cax = axes([l+w+0.05, b, 0.05, h]) # setup colorbar axes.
-colorbar(cax=cax) # draw colorbar
-axes(ax) # make the original axes current again
+cax = plt.axes([l+w+0.05, b, 0.05, h]) # setup colorbar axes.
+plt.colorbar(cax=cax) # draw colorbar
+plt.axes(ax) # make the original axes current again
# draw coastlines and political boundaries.
m.drawcoastlines()
# draw parallels and meridians
-parallels = arange(-60.,90,30.)
+parallels = np.arange(-60.,90,30.)
m.drawparallels(parallels,labels=[1,0,0,0])
-meridians = arange(0.,360.,60.)
+meridians = np.arange(0.,360.,60.)
m.drawmeridians(meridians,labels=[0,0,0,1])
# draw boundary around map region.
m.drawmapboundary()
-title('Robinson')
+plt.title('Robinson')
print 'plotting Robinson example ...'
print m.srs
-show()
+plt.show()
print 'done'
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|