Revision: 4411
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4411&view=rev
Author: jswhit
Date: 2007-11-21 12:52:25 -0800 (Wed, 21 Nov 2007)
Log Message:
-----------
added examples for 'Plotting on Maps' workbook chapter
Added Paths:
-----------
trunk/py4science/examples/basemap1.py
trunk/py4science/examples/basemap2.py
trunk/py4science/examples/basemap3.py
trunk/py4science/examples/basemap4.py
trunk/py4science/examples/basemap5.py
Added: trunk/py4science/examples/basemap1.py
===================================================================
--- trunk/py4science/examples/basemap1.py (rev 0)
+++ trunk/py4science/examples/basemap1.py 2007-11-21 20:52:25 UTC (rev
4411)
@@ -0,0 +1,28 @@
+import pylab, numpy
+from matplotlib.toolkits.basemap import Basemap
+
+# create figure.
+# background color will be used for 'wet' areas.
+fig = pylab.figure()
+fig.add_axes([0.1,0.1,0.8,0.8],axisbg='aqua')
+# create map by specifying lat/lon values at corners.
+resolution = 'l'
+lon_0 = -50
+lat_0 = 60
+projection = 'lcc'
+llcrnrlat, llcrnrlon = 8, -92
+urcrnrlat, urcrnrlon = 39, 63
+m = Basemap(lon_0=lon_0,lat_0=lat_0,\
+ llcrnrlat=llcrnrlat,llcrnrlon=llcrnrlon,\
+ urcrnrlat=urcrnrlat,urcrnrlon=urcrnrlon,\
+ resolution=resolution,projection=projection)
+# draw coastlines. Make liness a little thinner than default.
+m.drawcoastlines(linewidth=0.5)
+# fill continents.
+m.fillcontinents(color='coral')
+# draw states and countries.
+m.drawcountries()
+m.drawstates()
+pylab.title('map region specified using corner lat/lon values')
+pylab.savefig('basemap1.eps')
+pylab.savefig('basemap1.png')
Added: trunk/py4science/examples/basemap2.py
===================================================================
--- trunk/py4science/examples/basemap2.py (rev 0)
+++ trunk/py4science/examples/basemap2.py 2007-11-21 20:52:25 UTC (rev
4411)
@@ -0,0 +1,27 @@
+import pylab, numpy
+from matplotlib.toolkits.basemap import Basemap
+
+# create figure.
+# background color will be used for 'wet' areas.
+fig = pylab.figure()
+fig.add_axes([0.1,0.1,0.8,0.8],axisbg='aqua')
+# create map by specifying width and height in km.
+resolution = 'l'
+lon_0 = -50
+lat_0 = 60
+projection = 'lcc'
+width = 12000000
+height = 0.75*width
+m = Basemap(lon_0=lon_0,lat_0=lat_0,\
+ width=width,height=height,\
+ resolution=resolution,projection=projection)
+# draw coastlines.
+m.drawcoastlines(linewidth=0.5)
+# fill continents.
+m.fillcontinents(color='coral')
+# draw states and countries.
+m.drawcountries()
+m.drawstates()
+pylab.title('map region specified using width and height')
+pylab.savefig('basemap2.eps')
+pylab.savefig('basemap2.png')
Added: trunk/py4science/examples/basemap3.py
===================================================================
--- trunk/py4science/examples/basemap3.py (rev 0)
+++ trunk/py4science/examples/basemap3.py 2007-11-21 20:52:25 UTC (rev
4411)
@@ -0,0 +1,45 @@
+import pylab, numpy
+from matplotlib.toolkits.basemap import Basemap
+
+# create figure.
+# background color will be used for 'wet' areas.
+fig = pylab.figure()
+fig.add_axes([0.1,0.1,0.8,0.8],axisbg='aqua')
+# create map by specifying width and height in km.
+resolution = 'l'
+lon_0 = -50
+lat_0 = 60
+projection = 'lcc'
+width = 12000000
+height = 0.75*width
+m = Basemap(lon_0=lon_0,lat_0=lat_0,\
+ width=width,height=height,\
+ resolution=resolution,projection=projection)
+# nylat, nylon are lat/lon of New York
+nylat = 40.78
+nylon = -73.98
+# lonlat, lonlon are lat/lon of London.
+lonlat = 51.53
+lonlon = 0.08
+# convert these points to map projection coordinates
+# (using __call__ method of Basemap instance)
+ny_x, ny_y = m(nylon, nylat)
+lon_x, lon_y = m(lonlon, lonlat)
+# plot black dots at the two points.
+# make sure dots are drawn on top of other plot elements (zorder=10)
+m.scatter([ny_x,lon_x],[ny_y,lon_y],25,color='k',marker='o',zorder=10)
+# connect the dots along a great circle.
+m.drawgreatcircle(nylon,nylat,lonlon,lonlat,linewidth=2,color='k')
+# put the names of the cities to the left of each dot, offset
+# by a little. Use a bold font.
+pylab.text(ny_x-100000,ny_y+100000,'New York',fontsize=12,\
+ color='k',horizontalalignment='right',fontweight='bold')
+pylab.text(lon_x-100000,lon_y+100000,'London',fontsize=12,\
+ color='k',horizontalalignment='right',fontweight='bold')
+m.drawcoastlines(linewidth=0.5)
+m.fillcontinents(color='coral')
+m.drawcountries()
+m.drawstates()
+pylab.title('NY to London Great Circle')
+pylab.savefig('basemap3.eps')
+pylab.savefig('basemap3.png')
Added: trunk/py4science/examples/basemap4.py
===================================================================
--- trunk/py4science/examples/basemap4.py (rev 0)
+++ trunk/py4science/examples/basemap4.py 2007-11-21 20:52:25 UTC (rev
4411)
@@ -0,0 +1,29 @@
+import pylab, numpy
+from matplotlib.toolkits.basemap import Basemap
+# create figure.
+# background color will be used for 'wet' areas.
+fig = pylab.figure()
+fig.add_axes([0.1,0.1,0.8,0.8],axisbg='aqua')
+# create map by specifying width and height in km.
+resolution = 'l'
+lon_0 = -50
+lat_0 = 60
+projection = 'lcc'
+width = 12000000
+height = 0.75*width
+m = Basemap(lon_0=lon_0,lat_0=lat_0,\
+ width=width,height=height,\
+ resolution=resolution,projection=projection)
+m.drawcoastlines(linewidth=0.5)
+m.fillcontinents(color='coral')
+m.drawcountries()
+m.drawstates()
+# label meridians where they intersect the left, right and bottom
+# of the plot frame.
+m.drawmeridians(numpy.arange(-180,181,20),labels=[1,1,0,1])
+# label parallels where they intersect the left, right and top
+# of the plot frame.
+m.drawparallels(numpy.arange(-80,81,20),labels=[1,1,1,0])
+pylab.title('labelled meridians and parallels',y=1.075)
+pylab.savefig('basemap4.eps')
+pylab.savefig('basemap4.png')
Added: trunk/py4science/examples/basemap5.py
===================================================================
--- trunk/py4science/examples/basemap5.py (rev 0)
+++ trunk/py4science/examples/basemap5.py 2007-11-21 20:52:25 UTC (rev
4411)
@@ -0,0 +1,38 @@
+from matplotlib.toolkits.basemap import Basemap, NetCDFFile
+import pylab, numpy
+from numpy import ma
+
+# read in netCDF sea-surface temperature data
+ncfile = NetCDFFile('data/sst.nc')
+sstv = ncfile.variables['analysed_sst']
+sst = ma.masked_values(numpy.squeeze(sstv[:]), sstv._FillValue)
+sst = sstv.scale_factor*sst + sstv.add_offset
+lats = ncfile.variables['lat'][:]
+lons = ncfile.variables['lon'][:]
+print sst.shape, sst.min(), sst.max()
+
+# make sure middle of map region is middle of data grid.
+lon_0 = lons.mean()
+lat_0 = lats.mean()
+# set colormap
+cmap = pylab.cm.gist_ncar
+# create Basemap instance for mollweide projection.
+m = Basemap(projection='moll',lon_0=lon_0,lat_0=lat_0,resolution='l')
+# compute map projection coordinates of grid.
+x, y = m(*numpy.meshgrid(lons, lats))
+# plot with contour
+#CS = m.contour(x,y,sst,20,linewidths=0.5,colors='k')
+#CS = m.contourf(x,y,sst,20,cmap=cmap)
+# plot with pcolor
+im = m.pcolormesh(x,y,sst,shading='flat',cmap=cmap)
+# fill the continents (data is not defined there).
+m.fillcontinents(color='k',lake_color='k')
+# draw parallels and meridians.
+m.drawparallels(numpy.arange(-90.,120.,30.))
+m.drawmeridians(numpy.arange(0.,420.,60.))
+# draw line around map projection limb.
+m.drawmapboundary()
+# draw horizontal colorbar.
+pylab.colorbar(orientation='horizontal')
+pylab.savefig('basemap5.pdf') # eps files are too huge when pcolor used.
+pylab.savefig('basemap5.png')
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins