From: <js...@us...> - 2009-03-14 13:53:42
|
Revision: 6977 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6977&view=rev Author: jswhit Date: 2009-03-14 13:53:24 +0000 (Sat, 14 Mar 2009) Log Message: ----------- added shaded relief plot example. Modified Paths: -------------- trunk/toolkits/basemap/Changelog trunk/toolkits/basemap/MANIFEST.in trunk/toolkits/basemap/examples/README Added Paths: ----------- trunk/toolkits/basemap/examples/plotmap_shaded.py Modified: trunk/toolkits/basemap/Changelog =================================================================== --- trunk/toolkits/basemap/Changelog 2009-03-14 13:49:09 UTC (rev 6976) +++ trunk/toolkits/basemap/Changelog 2009-03-14 13:53:24 UTC (rev 6977) @@ -1,4 +1,5 @@ version 0.99.4 (not yet released) + * added new example "plotmap_shaded.py" (shaded relief plot). * added new example "plothighsandlows.py". * add fix_aspect kwarg to Basemap.__init__, when False axes.set_aspect is set to 'auto' instead of default 'equal'. Modified: trunk/toolkits/basemap/MANIFEST.in =================================================================== --- trunk/toolkits/basemap/MANIFEST.in 2009-03-14 13:49:09 UTC (rev 6976) +++ trunk/toolkits/basemap/MANIFEST.in 2009-03-14 13:53:24 UTC (rev 6977) @@ -40,6 +40,7 @@ include examples/plotmap.py include examples/plotmap_oo.py include examples/plotmap_masked.py +include examples/plotmap_shaded.py include examples/contour_demo.py include examples/customticks.py include examples/quiver_demo.py Modified: trunk/toolkits/basemap/examples/README =================================================================== --- trunk/toolkits/basemap/examples/README 2009-03-14 13:49:09 UTC (rev 6976) +++ trunk/toolkits/basemap/examples/README 2009-03-14 13:53:24 UTC (rev 6977) @@ -20,6 +20,9 @@ in test.py) which shows the ETOPO topography as an image on a Lambert Conformal projection (using imshow). +plotmap_shaded.py shows how to make a 'shaded relief' plot by specifying +the location of a lightsource. + plotmap_oo.py is a version of plotmap.py that does not import pylab - it uses the matplotlib OO interface instead. Added: trunk/toolkits/basemap/examples/plotmap_shaded.py =================================================================== --- trunk/toolkits/basemap/examples/plotmap_shaded.py (rev 0) +++ trunk/toolkits/basemap/examples/plotmap_shaded.py 2009-03-14 13:53:24 UTC (rev 6977) @@ -0,0 +1,48 @@ +# make shaded relief plot of etopo bathymetry/topography data on +# lambert conformal conic map projection. + +# the data is interpolated to the native projection grid. + +from mpl_toolkits.basemap import Basemap, shiftgrid +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.mlab as mlab +from matplotlib.colors import lightsource + +# read in topo data (on a regular lat/lon grid) +# longitudes go from 20 to 380. +topoin = mlab.load('etopo20data.gz') +lons = mlab.load('etopo20lons.gz') +lats = mlab.load('etopo20lats.gz') +# shift data so lons go from -180 to 180 instead of 20 to 380. +topoin,lons = shiftgrid(180.,topoin,lons,start=False) + +# setup of basemap ('lcc' = lambert conformal conic). +# use major and minor sphere radii from WGS84 ellipsoid. +m = Basemap(llcrnrlon=-145.5,llcrnrlat=1.,urcrnrlon=-2.566,urcrnrlat=46.352,\ + rsphere=(6378137.00,6356752.3142),\ + resolution='l',area_thresh=1000.,projection='lcc',\ + lat_1=50.,lon_0=-107.) +# transform to nx x ny regularly spaced native projection grid +nx = int((m.xmax-m.xmin)/40000.)+1; ny = int((m.ymax-m.ymin)/40000.)+1 +topodat,x,y = m.transform_scalar(topoin,lons,lats,nx,ny,returnxy=True) +ls = lightsource(azdeg = 90, altdeg = 20) +print topodat.shape +rgb = ls.shade(topodat, plt.cm.jet) +# create the figure. +fig=plt.figure(figsize=(8,8)) +# plot image over map with imshow. +im = m.imshow(rgb) +# draw coastlines and political boundaries. +m.drawcoastlines() +m.drawcountries() +# draw parallels and meridians. +# label on left, right and bottom of map. +parallels = np.arange(0.,80,20.) +m.drawparallels(parallels,labels=[1,1,0,1]) +meridians = np.arange(10.,360.,30.) +m.drawmeridians(meridians,labels=[1,1,0,1]) +# set title. +plt.title('ETOPO Shaded Relief - Lambert Conformal Conic') +#plt.savefig('plotmap.pdf') +plt.show() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |