From: <js...@us...> - 2008-05-20 12:22:22
|
Revision: 5197 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5197&view=rev Author: jswhit Date: 2008-05-20 05:22:09 -0700 (Tue, 20 May 2008) Log Message: ----------- more examples updated to numpy/pyplot namespace Modified Paths: -------------- trunk/toolkits/basemap/examples/ccsm_popgrid.py trunk/toolkits/basemap/examples/fillstates.py trunk/toolkits/basemap/examples/garp.py trunk/toolkits/basemap/examples/hurrtracks.py trunk/toolkits/basemap/examples/panelplot.py trunk/toolkits/basemap/examples/plot_tissot.py trunk/toolkits/basemap/examples/plotprecip.py trunk/toolkits/basemap/examples/plotsst.py trunk/toolkits/basemap/examples/pnganim.py trunk/toolkits/basemap/examples/polarmaps.py trunk/toolkits/basemap/examples/setwh.py trunk/toolkits/basemap/examples/show_colormaps.py trunk/toolkits/basemap/examples/testgdal.py Modified: trunk/toolkits/basemap/examples/ccsm_popgrid.py =================================================================== --- trunk/toolkits/basemap/examples/ccsm_popgrid.py 2008-05-20 11:52:12 UTC (rev 5196) +++ trunk/toolkits/basemap/examples/ccsm_popgrid.py 2008-05-20 12:22:09 UTC (rev 5197) @@ -20,10 +20,10 @@ POP grids are used extensively locally in oceanographic and ice models. """ -import pylab as pl from matplotlib import rcParams -from numpy import ma as MA -import numpy as N +from numpy import ma +import numpy as np +import matplotlib.pyplot as plt from mpl_toolkits.basemap import Basemap, NetCDFFile # read in data from netCDF file. @@ -36,17 +36,17 @@ fpin.close() # make longitudes monotonically increasing. -tlon = N.where(N.greater_equal(tlon,min(tlon[:,0])),tlon-360,tlon) +tlon = np.where(np.greater_equal(tlon,min(tlon[:,0])),tlon-360,tlon) # stack grids side-by-side (in longitiudinal direction), so # any range of longitudes may be plotted on a world map. -tlon = N.concatenate((tlon,tlon+360),1) -tlat = N.concatenate((tlat,tlat),1) -temp = MA.concatenate((temp,temp),1) +tlon = np.concatenate((tlon,tlon+360),1) +tlat = np.concatenate((tlat,tlat),1) +temp = ma.concatenate((temp,temp),1) tlon = tlon-360. -pl.figure(figsize=(6,8)) -pl.subplot(2,1,1) +plt.figure(figsize=(6,8)) +plt.subplot(2,1,1) # subplot 1 just shows POP grid cells. map = Basemap(projection='merc', lat_ts=20, llcrnrlon=-180, \ urcrnrlon=180, llcrnrlat=-84, urcrnrlat=84, resolution='c') @@ -55,22 +55,22 @@ map.fillcontinents(color='white') x, y = map(tlon,tlat) -im = map.pcolor(x,y,MA.masked_array(N.zeros(temp.shape,'f'), temp.mask),\ - shading='faceted',cmap=pl.cm.cool,vmin=0,vmax=0) +im = map.pcolor(x,y,ma.masked_array(np.zeros(temp.shape,'f'), temp.mask),\ + shading='faceted',cmap=plt.cm.cool,vmin=0,vmax=0) # disclaimer: these are not really the grid cells because of the # way pcolor interprets the x and y args. -pl.title('(A) CCSM POP Grid Cells') +plt.title('(A) CCSM POP Grid Cells') # subplot 2 is a contour plot of surface temperature from the # CCSM ocean model. -pl.subplot(2,1,2) +plt.subplot(2,1,2) map.drawcoastlines() map.fillcontinents(color='white') CS1 = map.contourf(x,y,temp,15) CS2 = map.contour(x,y,temp,15,colors='black',linewidths=0.5) -pl.title('(B) Surface Temp contours on POP Grid') +plt.title('(B) Surface Temp contours on POP Grid') -pl.show() -#pl.savefig('ccsm_popgrid.ps') +plt.show() +#plt.savefig('ccsm_popgrid.ps') Modified: trunk/toolkits/basemap/examples/fillstates.py =================================================================== --- trunk/toolkits/basemap/examples/fillstates.py 2008-05-20 11:52:12 UTC (rev 5196) +++ trunk/toolkits/basemap/examples/fillstates.py 2008-05-20 12:22:09 UTC (rev 5197) @@ -1,5 +1,5 @@ -import pylab as p -import numpy +import numpy as np +import matplotlib.pyplot as plt from mpl_toolkits.basemap import Basemap as Basemap from matplotlib.colors import rgb2hex from matplotlib.patches import Polygon @@ -68,7 +68,7 @@ # choose a color for each state based on population density. colors={} statenames=[] -cmap = p.cm.hot # use 'hot' colormap +cmap = plt.cm.hot # use 'hot' colormap vmin = 0; vmax = 450 # set range. print m.states_info[0].keys() for shapedict in m.states_info: @@ -79,10 +79,10 @@ # calling colormap with value between 0 and 1 returns # rgba value. Invert color range (hot colors are high # population), take sqrt root to spread out colors more. - colors[statename] = cmap(1.-p.sqrt((pop-vmin)/(vmax-vmin)))[:3] + colors[statename] = cmap(1.-np.sqrt((pop-vmin)/(vmax-vmin)))[:3] statenames.append(statename) # cycle through state names, color each one. -ax = p.gca() # get current axes instance +ax = plt.gca() # get current axes instance for nshape,seg in enumerate(m.states): # skip DC and Puerto Rico. if statenames[nshape] not in ['District of Columbia','Puerto Rico']: @@ -90,7 +90,7 @@ poly = Polygon(seg,facecolor=color,edgecolor=color) ax.add_patch(poly) # draw meridians and parallels. -m.drawparallels(numpy.arange(25,65,20),labels=[1,0,0,0]) -m.drawmeridians(numpy.arange(-120,-40,20),labels=[0,0,0,1]) -p.title('Filling State Polygons by Population Density') -p.show() +m.drawparallels(np.arange(25,65,20),labels=[1,0,0,0]) +m.drawmeridians(np.arange(-120,-40,20),labels=[0,0,0,1]) +plt.title('Filling State Polygons by Population Density') +plt.show() Modified: trunk/toolkits/basemap/examples/garp.py =================================================================== --- trunk/toolkits/basemap/examples/garp.py 2008-05-20 11:52:12 UTC (rev 5196) +++ trunk/toolkits/basemap/examples/garp.py 2008-05-20 12:22:09 UTC (rev 5197) @@ -1,5 +1,6 @@ from mpl_toolkits.basemap import Basemap -from pylab import title, show, arange, pi +import numpy as np +import matplotlib.pyplot as plt # the shortest route from the center of the map # to any other point is a straight line in the azimuthal @@ -30,11 +31,11 @@ m.drawcoastlines(linewidth=0.5) m.fillcontinents(color='coral',lake_color='aqua') # 20 degree graticule. -m.drawparallels(arange(-80,81,20)) -m.drawmeridians(arange(-180,180,20)) +m.drawparallels(np.arange(-80,81,20)) +m.drawmeridians(np.arange(-180,180,20)) # draw a black dot at the center. xpt, ypt = m(lon_0, lat_0) m.plot([xpt],[ypt],'ko') # draw the title. -title('The World According to Garp in '+location) -show() +plt.title('The World According to Garp in '+location) +plt.show() Modified: trunk/toolkits/basemap/examples/hurrtracks.py =================================================================== --- trunk/toolkits/basemap/examples/hurrtracks.py 2008-05-20 11:52:12 UTC (rev 5196) +++ trunk/toolkits/basemap/examples/hurrtracks.py 2008-05-20 12:22:09 UTC (rev 5197) @@ -1,16 +1,17 @@ """ draw Atlantic Hurricane Tracks for storms that reached Cat 4 or 5. part of the track for which storm is cat 4 or 5 is shown red. -ESRI shapefile data from http://www.nationalatlas.gov/atlasftp.html +ESRI shapefile data from http://www.nationalatlas.gov/atlasftplt.html """ -import pylab as p +import numpy as np +import matplotlib.pyplot as plt from mpl_toolkits.basemap import Basemap as Basemap -# Lambert Conformal Conic map. +# Lambert Conformal Conic maplt. m = Basemap(llcrnrlon=-100.,llcrnrlat=0.,urcrnrlon=-20.,urcrnrlat=57., projection='lcc',lat_1=20.,lat_2=40.,lon_0=-60., resolution ='l',area_thresh=1000.) # create figure. -fig=p.figure() +fig=plt.figure() # read shapefile. shp_info = m.readshapefile('huralll020','hurrtracks',drawbounds=False) print shp_info @@ -32,15 +33,15 @@ xx,yy = zip(*shape) # show part of track where storm > Cat 4 as thick red. if cat in ['H4','H5']: - p.plot(xx,yy,linewidth=1.5,color='r') + plt.plot(xx,yy,linewidth=1.5,color='r') elif cat in ['H1','H2','H3']: - p.plot(xx,yy,color='k') + plt.plot(xx,yy,color='k') # draw coastlines, meridians and parallels. m.drawcoastlines() m.drawcountries() m.drawmapboundary(fill_color='#99ffff') m.fillcontinents(color='#cc9966',lake_color='#99ffff') -m.drawparallels(p.arange(10,70,20),labels=[1,1,0,0]) -m.drawmeridians(p.arange(-100,0,20),labels=[0,0,0,1]) -p.title('Atlantic Hurricane Tracks (Storms Reaching Category 4, 1851-2004)') -p.show() +m.drawparallels(np.arange(10,70,20),labels=[1,1,0,0]) +m.drawmeridians(np.arange(-100,0,20),labels=[0,0,0,1]) +plt.title('Atlantic Hurricane Tracks (Storms Reaching Category 4, 1851-2004)') +plt.show() Modified: trunk/toolkits/basemap/examples/panelplot.py =================================================================== --- trunk/toolkits/basemap/examples/panelplot.py 2008-05-20 11:52:12 UTC (rev 5196) +++ trunk/toolkits/basemap/examples/panelplot.py 2008-05-20 12:22:09 UTC (rev 5197) @@ -1,14 +1,16 @@ from mpl_toolkits.basemap import Basemap from matplotlib import rcParams from matplotlib.ticker import MultipleLocator -import pylab as P +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.mlab as mlab # 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) +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. @@ -18,29 +20,29 @@ rcParams['figure.subplot.wspace'] = 0.5 # more width between subplots # create new figure -fig=P.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=P.cm.Spectral) +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 = 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 +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 = P.arange(0.,90.,delat).tolist()+\ - P.arange(-delat,-90,-delat).tolist() +circles = np.arange(0.,90.,delat).tolist()+\ + np.arange(-delat,-90,-delat).tolist() mnh.drawparallels(circles,labels=[1,0,0,0]) delon = 45. -meridians = P.arange(0,360,delon) +meridians = np.arange(0,360,delon) mnh.drawmeridians(meridians,labels=[1,0,0,1]) -P.title('NH 500 hPa Height (cm.Spectral)') +plt.title('NH 500 hPa Height (cm.Spectral)') # panel 2 msh = Basemap(lon_0=-105,boundinglat=-20., @@ -48,17 +50,17 @@ 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) +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 = 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 +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]) -P.title('SH 500 hPa Height (cm.Spectral)') +plt.title('SH 500 hPa Height (cm.Spectral)') # 2-panel plot, oriented horizontally, colorbar on right. @@ -68,33 +70,33 @@ rcParams['figure.subplot.top'] = 0.85 # panel 1 -fig = P.figure() +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=P.cm.RdBu) +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 = 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 +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]) -P.title('NH 500 hPa Height (cm.RdBu)') +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=P.cm.RdBu) +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 = 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 +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]) -P.title('SH 500 hPa Height (cm.RdBu)') -P.show() +plt.title('SH 500 hPa Height (cm.RdBu)') +plt.show() Modified: trunk/toolkits/basemap/examples/plot_tissot.py =================================================================== --- trunk/toolkits/basemap/examples/plot_tissot.py 2008-05-20 11:52:12 UTC (rev 5196) +++ trunk/toolkits/basemap/examples/plot_tissot.py 2008-05-20 12:22:09 UTC (rev 5197) @@ -1,4 +1,5 @@ -import pylab as p +import numpy as np +import matplotlib.pyplot as plt from mpl_toolkits.basemap import Basemap as Basemap from matplotlib.patches import Polygon @@ -13,44 +14,44 @@ # adapted from http://www.perrygeo.net/wordpress/?p=4 # create new figure -fig=p.figure() +fig=plt.figure() m = Basemap(llcrnrlon=-180,llcrnrlat=-80,urcrnrlon=180,urcrnrlat=80, projection='cyl') shp_info = m.readshapefile('tissot','tissot',drawbounds=True) -ax = p.gca() +ax = plt.gca() for nshape,seg in enumerate(m.tissot): poly = Polygon(seg,facecolor='green',zorder=10) ax.add_patch(poly) # draw meridians and parallels. -m.drawparallels(p.arange(-90,91,30),labels=[1,0,0,0]) -m.drawmeridians(p.arange(-180,180,60),labels=[0,0,0,1]) +m.drawparallels(np.arange(-90,91,30),labels=[1,0,0,0]) +m.drawmeridians(np.arange(-180,180,60),labels=[0,0,0,1]) m.drawcoastlines() m.fillcontinents() -p.title('Tissot Diagram - Cylindrical Equal Area') +plt.title('Tissot Diagram - Cylindrical Equal Area') print 'plot Cylindrical Equidistant Equal Area Tissot diagram ...' # create new figure -fig=p.figure() +fig=plt.figure() m = Basemap(llcrnrlon=-180,llcrnrlat=-70,urcrnrlon=180,urcrnrlat=70, projection='merc',lat_ts=20) shp_info = m.readshapefile('tissot','tissot',drawbounds=True) -ax = p.gca() +ax = plt.gca() for nshape,seg in enumerate(m.tissot): poly = Polygon(seg,facecolor='green',zorder=10) ax.add_patch(poly) # draw meridians and parallels. -m.drawparallels(p.arange(-90,91,30),labels=[1,0,0,0]) -m.drawmeridians(p.arange(-180,180,60),labels=[0,0,0,1]) +m.drawparallels(np.arange(-90,91,30),labels=[1,0,0,0]) +m.drawmeridians(np.arange(-180,180,60),labels=[0,0,0,1]) m.drawcoastlines() m.fillcontinents() -p.title('Tissot Diagram - Mercator Conformal') +plt.title('Tissot Diagram - Mercator Conformal') print 'plot Mercator Conformal Tissot diagram ...' # create new figure -fig=p.figure() +fig=plt.figure() m = Basemap(lon_0=-60,lat_0=45,projection='ortho') shp_info = m.readshapefile('tissot','tissot',drawbounds=False) -ax = p.gca() +ax = plt.gca() for nshape,seg in enumerate(m.tissot): xx,yy = zip(*seg) if max(xx) < 1.e20 and max(yy) < 1.e20: @@ -58,42 +59,42 @@ ax.add_patch(poly) m.drawcoastlines() m.fillcontinents() -m.drawparallels(p.arange(-90,91,30)) -m.drawmeridians(p.arange(-180,180,30)) -p.title('Tissot Diagram - Orthographic') +m.drawparallels(np.arange(-90,91,30)) +m.drawmeridians(np.arange(-180,180,30)) +plt.title('Tissot Diagram - Orthographic') m.drawmapboundary() -p.gca().set_frame_on(True) +plt.gca().set_frame_on(True) print 'plot Orthographic Tissot diagram ...' # create new figure -fig=p.figure() +fig=plt.figure() m = Basemap(lon_0=270,lat_0=90,boundinglat=10,projection='npstere') shp_info = m.readshapefile('tissot','tissot',drawbounds=True) -ax = p.gca() +ax = plt.gca() for nshape,seg in enumerate(m.tissot): poly = Polygon(seg,facecolor='green',zorder=10) ax.add_patch(poly) # draw meridians and parallels. -m.drawparallels(p.arange(-90,91,30),labels=[1,0,0,0]) -m.drawmeridians(p.arange(-180,180,30),labels=[0,0,0,1]) +m.drawparallels(np.arange(-90,91,30),labels=[1,0,0,0]) +m.drawmeridians(np.arange(-180,180,30),labels=[0,0,0,1]) m.drawcoastlines() m.fillcontinents() -p.title('Tissot Diagram - North Polar Stereographic Conformal') +plt.title('Tissot Diagram - North Polar Stereographic Conformal') print 'plot North Polar Stereographic Conformal Tissot diagram ...' # create new figure -fig=p.figure() +fig=plt.figure() m = Basemap(lon_0=270,lat_0=90,boundinglat=10,projection='nplaea') shp_info = m.readshapefile('tissot','tissot',drawbounds=True) -ax = p.gca() +ax = plt.gca() for nshape,seg in enumerate(m.tissot): poly = Polygon(seg,facecolor='green',zorder=10) ax.add_patch(poly) # draw meridians and parallels. -m.drawparallels(p.arange(-90,91,30),labels=[1,0,0,0]) -m.drawmeridians(p.arange(-180,180,30),labels=[0,0,0,1]) +m.drawparallels(np.arange(-90,91,30),labels=[1,0,0,0]) +m.drawmeridians(np.arange(-180,180,30),labels=[0,0,0,1]) m.drawcoastlines() m.fillcontinents() -p.title('Tissot Diagram - North Polar Lambert Azimuthal Equal Area') +plt.title('Tissot Diagram - North Polar Lambert Azimuthal Equal Area') print 'plot North Polar Lambert Azimuthal Equal Area Tissot diagram ...' -p.show() +plt.show() Modified: trunk/toolkits/basemap/examples/plotprecip.py =================================================================== --- trunk/toolkits/basemap/examples/plotprecip.py 2008-05-20 11:52:12 UTC (rev 5196) +++ trunk/toolkits/basemap/examples/plotprecip.py 2008-05-20 12:22:09 UTC (rev 5197) @@ -1,5 +1,7 @@ from mpl_toolkits.basemap import Basemap, cm, NetCDFFile -import pylab, copy +import numpy as np +import matplotlib.pyplot as plt +import copy from matplotlib import rcParams # make tick labels smaller @@ -29,20 +31,20 @@ llcrnrlon=loncorners[0],urcrnrlon=loncorners[2],\ rsphere=6371200.,resolution='l',area_thresh=10000) # create figure -fig = pylab.figure(figsize=(6,8.5)) -pylab.subplot(211) -ax = pylab.gca() +fig = plt.figure(figsize=(6,8.5)) +plt.subplot(211) +ax = plt.gca() # draw coastlines, state and country boundaries, edge of map. m.drawcoastlines() m.drawstates() m.drawcountries() # draw parallels. delat = 10.0 -parallels = pylab.arange(0.,90,delat) +parallels = np.arange(0.,90,delat) m.drawparallels(parallels,labels=[1,0,0,0],fontsize=10) # draw meridians delon = 10. -meridians = pylab.arange(180.,360.,delon) +meridians = np.arange(180.,360.,delon) m.drawmeridians(meridians,labels=[0,0,0,1],fontsize=10) ny = data.shape[0]; nx = data.shape[1] lons, lats = m.makegrid(nx, ny) # get lat/lons of ny by nx evenly space grid. @@ -53,15 +55,15 @@ # new axis for colorbar. pos = ax.get_position() l, b, w, h = pos.bounds -cax = pylab.axes([l+w+0.025, b, 0.025, h]) # setup colorbar axes +cax = plt.axes([l+w+0.025, b, 0.025, h]) # setup colorbar axes # draw colorbar. -pylab.colorbar(cs, cax, format='%g', ticks=clevs, drawedges=False) -pylab.axes(ax) # make the original axes current again +plt.colorbar(cs, cax, format='%g', ticks=clevs, drawedges=False) +plt.axes(ax) # make the original axes current again # plot title -pylab.title(plottitle+'- contourf',fontsize=10) +plt.title(plottitle+'- contourf',fontsize=10) -pylab.subplot(212) -ax = pylab.gca() +plt.subplot(212) +ax = plt.gca() # draw coastlines, state and country boundaries, edge of map. m.drawcoastlines() m.drawstates() @@ -79,15 +81,15 @@ # new axis for colorbar. pos = ax.get_position() l, b, w, h = pos.bounds -cax = pylab.axes([l+w+0.025, b, 0.025, h]) # setup colorbar axes +cax = plt.axes([l+w+0.025, b, 0.025, h]) # setup colorbar axes # using im2, not im (hack to prevent colors from being # too compressed at the low end on the colorbar - results # from highly nonuniform colormap) -pylab.colorbar(im2, cax, format='%d') # draw colorbar -pylab.axes(ax) # make the original axes current again +plt.colorbar(im2, cax, format='%d') # draw colorbar +plt.axes(ax) # make the original axes current again # reset colorbar tick labels (hack to get -cax.set_yticks(pylab.linspace(0,1,len(clevs))) +cax.set_yticks(np.linspace(0,1,len(clevs))) cax.set_yticklabels(['%g' % clev for clev in clevs]) # plot title -pylab.title(plottitle+' - imshow',fontsize=10) -pylab.show() # display onscreen. +plt.title(plottitle+' - imshow',fontsize=10) +plt.show() # display onscreen. Modified: trunk/toolkits/basemap/examples/plotsst.py =================================================================== --- trunk/toolkits/basemap/examples/plotsst.py 2008-05-20 11:52:12 UTC (rev 5196) +++ trunk/toolkits/basemap/examples/plotsst.py 2008-05-20 12:22:09 UTC (rev 5197) @@ -1,5 +1,7 @@ from mpl_toolkits.basemap import Basemap, NetCDFFile -import pylab, numpy, sys +import numpy as np +import matplotlib.pyplot as plt +import sys # read in sea-surface temperature and ice data # can be a local file, a URL for a remote opendap dataset, # or (if PyNIO is installed) a GRIB or HDF file. @@ -25,29 +27,29 @@ delat = lats[1]-lats[0] lons = (lons - 0.5*delon).tolist() lons.append(lons[-1]+delon) -lons = numpy.array(lons,numpy.float64) +lons = np.array(lons,np.float64) lats = (lats - 0.5*delat).tolist() lats.append(lats[-1]+delat) -lats = numpy.array(lats,numpy.float64) +lats = np.array(lats,np.float64) # create Basemap instance for mollweide projection. # coastlines not used, so resolution set to None to skip # continent processing (this speeds things up a bit) #m = Basemap(projection='ortho',lon_0=-110,lat_0=20,resolution=None) m = Basemap(projection='moll',lon_0=lons.mean(),lat_0=0,resolution=None) # compute map projection coordinates of grid. -x, y = m(*numpy.meshgrid(lons, lats)) +x, y = m(*np.meshgrid(lons, lats)) # draw line around map projection limb. # color background of map projection region. # missing values over land will show up this color. m.drawmapboundary(fill_color='0.3') # plot ice, then with pcolor -im1 = m.pcolor(x,y,sst,shading='flat',cmap=pylab.cm.jet) -im2 = m.pcolor(x,y,ice,shading='flat',cmap=pylab.cm.gist_gray) +im1 = m.pcolor(x,y,sst,shading='flat',cmap=plt.cm.jet) +im2 = m.pcolor(x,y,ice,shading='flat',cmap=plt.cm.gist_gray) # draw parallels and meridians, but don't bother labelling them. -m.drawparallels(numpy.arange(-90.,120.,30.)) -m.drawmeridians(numpy.arange(0.,420.,60.)) +m.drawparallels(np.arange(-90.,120.,30.)) +m.drawmeridians(np.arange(0.,420.,60.)) # draw horizontal colorbar. -pylab.colorbar(im1,orientation='horizontal') +plt.colorbar(im1,orientation='horizontal') # display the plot with a title. -pylab.title('SST and ICE analysis for %s'%date) -pylab.show() +plt.title('SST and ICE analysis for %s'%date) +plt.show() Modified: trunk/toolkits/basemap/examples/pnganim.py =================================================================== --- trunk/toolkits/basemap/examples/pnganim.py 2008-05-20 11:52:12 UTC (rev 5196) +++ trunk/toolkits/basemap/examples/pnganim.py 2008-05-20 12:22:09 UTC (rev 5197) @@ -4,8 +4,9 @@ # reads data over http - needs an active internet connection. -import numpy -import pylab +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.mlab as mlab from numpy import ma import datetime, sys, time, subprocess from mpl_toolkits.basemap import Basemap, shiftgrid, NetCDFFile, num2date @@ -62,40 +63,40 @@ vin = vdata[ntime1:ntime2+1,0,:,:] datelabels = dates[ntime1:ntime2+1] # add cyclic points -slp = numpy.zeros((slpin.shape[0],slpin.shape[1],slpin.shape[2]+1),numpy.float64) +slp = np.zeros((slpin.shape[0],slpin.shape[1],slpin.shape[2]+1),np.float64) slp[:,:,0:-1] = slpin; slp[:,:,-1] = slpin[:,:,0] -u = numpy.zeros((uin.shape[0],uin.shape[1],uin.shape[2]+1),numpy.float64) +u = np.zeros((uin.shape[0],uin.shape[1],uin.shape[2]+1),np.float64) u[:,:,0:-1] = uin; u[:,:,-1] = uin[:,:,0] -v = numpy.zeros((vin.shape[0],vin.shape[1],vin.shape[2]+1),numpy.float64) +v = np.zeros((vin.shape[0],vin.shape[1],vin.shape[2]+1),np.float64) v[:,:,0:-1] = vin; v[:,:,-1] = vin[:,:,0] -longitudes.append(360.); longitudes = numpy.array(longitudes) +longitudes.append(360.); longitudes = np.array(longitudes) # make 2-d grid of lons, lats -lons, lats = numpy.meshgrid(longitudes,latitudes) +lons, lats = np.meshgrid(longitudes,latitudes) print 'min/max slp,u,v' print slp.min(), slp.max() print uin.min(), uin.max() print vin.min(), vin.max() print 'dates' print datelabels -# make orthographic basemapylab. +# make orthographic basemaplt. m = Basemap(resolution='c',projection='ortho',lat_0=60.,lon_0=-60.) -pylab.ion() # interactive mode on. +plt.ion() # interactive mode on. uin = udata[ntime1:ntime2+1,0,:,:] vin = vdata[ntime1:ntime2+1,0,:,:] datelabels = dates[ntime1:ntime2+1] -# make orthographic basemapylab. +# make orthographic basemaplt. m = Basemap(resolution='c',projection='ortho',lat_0=60.,lon_0=-60.) -pylab.ion() # interactive mode on. +plt.ion() # interactive mode on. # create figure, add axes (leaving room for colorbar on right) -fig = pylab.figure() +fig = plt.figure() ax = fig.add_axes([0.1,0.1,0.7,0.7]) # set desired contour levels. -clevs = numpy.arange(960,1061,5) +clevs = np.arange(960,1061,5) # compute native x,y coordinates of grid. x, y = m(lons, lats) # define parallels and meridians to draw. -parallels = numpy.arange(-80.,90,20.) -meridians = numpy.arange(0.,360.,20.) +parallels = np.arange(-80.,90,20.) +meridians = np.arange(0.,360.,20.) # number of repeated frames at beginning and end is n1. nframe = 0; n1 = 10 pos = ax.get_position() @@ -104,42 +105,42 @@ # 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=pylab.cm.RdBu_r,animated=True) + CS = m.contourf(x,y,slp[nt,:,:],clevs,cmap=plt.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 mapylab. + # plot wind vectors over maplt. #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 upylab. + # in longitude). Otherwise, interpolation is messed uplt. 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 mapylab. + # plot wind vectors over maplt. Q = m.quiver(xx,yy,urot,vrot,scale=500) # make quiver key. - qk = pylab.quiverkey(Q, 0.1, 0.1, 20, '20 m/s', labelpos='W') + qk = plt.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) - pylab.title('SLP and Wind Vectors '+date) + plt.title('SLP and Wind Vectors '+date) if nt == 0: # plot colorbar on a separate axes (only for first frame) - cax = pylab.axes([l+w-0.05, b, 0.03, h]) # setup colorbar axes + cax = plt.axes([l+w-0.05, b, 0.03, h]) # setup colorbar axes fig.colorbar(CS,drawedges=True, cax=cax) # draw colorbar cax.text(0.0,-0.05,'mb') - pylab.axes(ax) # reset current axes - pylab.draw() # draw the plot + plt.axes(ax) # reset current axes + plt.draw() # draw the plot # save first and last frame n1 times # (so gif animation pauses at beginning and end) if nframe == 0 or nt == slp.shape[0]-1: for n in range(n1): - pylab.savefig('anim%03i'%nframe+'.png') + plt.savefig('anim%03i'%nframe+'.png') nframe = nframe + 1 else: - pylab.savefig('anim%03i'%nframe+'.png') + plt.savefig('anim%03i'%nframe+'.png') nframe = nframe + 1 ax.clear() # clear the axes for the next plot. Modified: trunk/toolkits/basemap/examples/polarmaps.py =================================================================== --- trunk/toolkits/basemap/examples/polarmaps.py 2008-05-20 11:52:12 UTC (rev 5196) +++ trunk/toolkits/basemap/examples/polarmaps.py 2008-05-20 12:22:09 UTC (rev 5197) @@ -6,17 +6,18 @@ # illustrates special-case polar-centric projections. from mpl_toolkits.basemap import Basemap -from pylab import title, colorbar, show, axes, cm, load, arange, \ - figure, ravel, meshgrid +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.mlab as mlab # read in topo data (on a regular lat/lon grid) # longitudes go from 20 to 380. -etopo = load('etopo20data.gz') -lons = load('etopo20lons.gz') -lats = load('etopo20lats.gz') +etopo = mlab.load('etopo20data.gz') +lons = mlab.load('etopo20lons.gz') +lats = mlab.load('etopo20lats.gz') print 'min/max etopo20 data:' -print min(ravel(etopo)),max(ravel(etopo)) +print etopo.min(),etopo.max() # these are the 4 polar projections projs = ['laea','stere','aeqd','ortho'] # short names @@ -36,7 +37,7 @@ lat_0 = 90. bounding_lat = 20. # loop over projections, one for each panel of the figure. - fig = figure(figsize=(8,8)) + fig = plt.figure(figsize=(8,8)) npanel = 0 for proj,projname in zip(projs,projnames): npanel = npanel + 1 @@ -53,18 +54,18 @@ m = Basemap(boundinglat=bounding_lat,lon_0=lon_0,\ resolution='c',area_thresh=10000.,projection=projection) # compute native map projection coordinates for lat/lon grid. - x,y = m(*meshgrid(lons,lats)) + x,y = m(*np.meshgrid(lons,lats)) ax = fig.add_subplot(2,2,npanel) # make filled contour plot. - cs = m.contourf(x,y,etopo,20,cmap=cm.jet) + cs = m.contourf(x,y,etopo,20,cmap=plt.cm.jet) # draw coastlines. m.drawcoastlines() # draw parallels and meridians. - m.drawparallels(arange(-80.,90,20.)) - m.drawmeridians(arange(0.,360.,60.)) + m.drawparallels(np.arange(-80.,90,20.)) + m.drawmeridians(np.arange(0.,360.,60.)) # draw boundary around map region. m.drawmapboundary() # draw title. - title(hem+' Polar '+projname,y=1.05,fontsize=12) + plt.title(hem+' Polar '+projname,y=1.05,fontsize=12) print 'plotting '+hem+' Polar '+projname+' basemap ...' -show() +plt.show() Modified: trunk/toolkits/basemap/examples/setwh.py =================================================================== --- trunk/toolkits/basemap/examples/setwh.py 2008-05-20 11:52:12 UTC (rev 5196) +++ trunk/toolkits/basemap/examples/setwh.py 2008-05-20 12:22:09 UTC (rev 5197) @@ -2,7 +2,8 @@ # to the Basemap constructor. from mpl_toolkits.basemap import Basemap -from pylab import arange, show, title, figure +import numpy as np +import matplotlib.pyplot as plt # setup projection parameters lat_0 = 40. @@ -10,14 +11,14 @@ width = 6000000. height = 2.*width/3. delat = 25. -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() delon = 30. -meridians = arange(10.,360.,delon) +meridians = np.arange(10.,360.,delon) npanel = 0 # plots of the US. projs = ['lcc','aeqd','aea','laea','eqdc','stere'] -fig = figure(figsize=(7,7)) +fig = plt.figure(figsize=(7,7)) for proj in projs: m = Basemap(width=width,height=height, resolution='c',projection=proj,\ @@ -30,6 +31,6 @@ m.drawstates() m.drawparallels(circles) m.drawmeridians(meridians) - title('proj = '+proj+' centered on %sW, %sN' % (lon_0,lat_0),fontsize=10) + plt.title('proj = '+proj+' centered on %sW, %sN' % (lon_0,lat_0),fontsize=10) -show() +plt.show() Modified: trunk/toolkits/basemap/examples/show_colormaps.py =================================================================== --- trunk/toolkits/basemap/examples/show_colormaps.py 2008-05-20 11:52:12 UTC (rev 5196) +++ trunk/toolkits/basemap/examples/show_colormaps.py 2008-05-20 12:22:09 UTC (rev 5197) @@ -1,16 +1,17 @@ -import numpy, pylab +import numpy as np +import matplotlib.pyplot as plt from mpl_toolkits.basemap import cm -a=numpy.outer(numpy.arange(0,1,0.01),numpy.ones(10)) -pylab.figure(figsize=(10,7)) -pylab.subplots_adjust(top=0.8,bottom=0.05,left=0.01,right=0.99) +a=np.outer(np.arange(0,1,0.01),np.ones(10)) +plt.figure(figsize=(10,7)) +plt.subplots_adjust(top=0.8,bottom=0.05,left=0.01,right=0.99) maps=[m for m in cm.datad.keys() if not m.endswith("_r")] maps.sort() l=len(maps)+1 i=1 for m in maps: - pylab.subplot(1,l,i) - pylab.axis("off") - pylab.imshow(a,aspect='auto',cmap=cm.__dict__[m],origin="lower") - pylab.title(m,rotation=90,fontsize=10) + plt.subplot(1,l,i) + plt.axis("off") + plt.imshow(a,aspect='auto',cmap=cm.__dict__[m],origin="lower") + plt.title(m,rotation=90,fontsize=10) i=i+1 -pylab.show() +plt.show() Modified: trunk/toolkits/basemap/examples/testgdal.py =================================================================== --- trunk/toolkits/basemap/examples/testgdal.py 2008-05-20 11:52:12 UTC (rev 5196) +++ trunk/toolkits/basemap/examples/testgdal.py 2008-05-20 12:22:09 UTC (rev 5197) @@ -3,13 +3,14 @@ gdal (http://gdal.maptools.org). Data files must be downloaded manually from USGS: -http://edcftp.cr.usgs.gov/pub/data/DEM/250/D/denver-w.gz -http://edcftp.cr.usgs.gov/pub/data/nationalatlas/countyp020.tar.gz +http://edcftplt.cr.usgs.gov/pub/data/DEM/250/D/denver-w.gz +http://edcftplt.cr.usgs.gov/pub/data/nationalatlas/countyp020.tar.gz """ import gdal from mpl_toolkits.basemap import Basemap from gdalconst import * -import pylab as p +import numpy as np +import matplotlib.pyplot as plt # download from # http://edcftp.cr.usgs.gov/pub/data/DEM/250/D/denver-w.gz @@ -26,17 +27,17 @@ m = Basemap(llcrnrlon=llcrnrlon,llcrnrlat=llcrnrlat,urcrnrlon=urcrnrlon,urcrnrlat=urcrnrlat,projection='cyl') # create a figure, add an axes # (leaving room for a colorbar). -fig = p.figure() +fig = plt.figure() ax = fig.add_axes([0.1,0.1,0.75,0.75]) # plot image from DEM over map. im = m.imshow(array,origin='upper') # make a colorbar. -cax = p.axes([0.875, 0.1, 0.05, 0.75]) # setup colorbar axes. -p.colorbar(cax=cax) # draw colorbar -p.axes(ax) # make the original axes current again +cax = plt.axes([0.875, 0.1, 0.05, 0.75]) # setup colorbar axes. +plt.colorbar(cax=cax) # draw colorbar +plt.axes(ax) # make the original axes current again # draw meridians and parallels. -m.drawmeridians(p.linspace(llcrnrlon+0.1,urcrnrlon-0.1,5),labels=[0,0,0,1],fmt='%4.2f') -m.drawparallels(p.linspace(llcrnrlat+0.1,urcrnrlat-0.1,5),labels=[1,0,0,0],fmt='%4.2f') +m.drawmeridians(np.linspace(llcrnrlon+0.1,urcrnrlon-0.1,5),labels=[0,0,0,1],fmt='%4.2f') +m.drawparallels(np.linspace(llcrnrlat+0.1,urcrnrlat-0.1,5),labels=[1,0,0,0],fmt='%4.2f') # plot county boundaries from # http://edcftp.cr.usgs.gov/pub/data/nationalatlas/countyp020.tar.gz shp_info = m.readshapefile('countyp020','counties',drawbounds=True,linewidth=1.0) @@ -46,6 +47,6 @@ x,y = m(lons,lats) m.plot(x,y,'ko') for name,xx,yy in zip(names,x,y): - p.text(xx+0.01,yy+0.01,name) -p.title(gd.GetDescription()+' USGS DEM with county boundaries') -p.show() + plt.text(xx+0.01,yy+0.01,name) +plt.title(gd.GetDescription()+' USGS DEM with county boundaries') +plt.show() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |