Revision: 4424
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4424&view=rev
Author: jswhit
Date: 2007-11-23 05:38:18 -0800 (Fri, 23 Nov 2007)
Log Message:
-----------
add basemap skeletons
Modified Paths:
--------------
trunk/py4science/examples/skel/basemap2_skel.py
Added Paths:
-----------
trunk/py4science/examples/skel/basemap3_skel.py
trunk/py4science/examples/skel/basemap4_skel.py
trunk/py4science/examples/skel/basemap5_skel.py
Modified: trunk/py4science/examples/skel/basemap2_skel.py
===================================================================
--- trunk/py4science/examples/skel/basemap2_skel.py 2007-11-22 19:37:56 UTC
(rev 4423)
+++ trunk/py4science/examples/skel/basemap2_skel.py 2007-11-23 13:38:18 UTC
(rev 4424)
@@ -1,15 +1,16 @@
import pylab, numpy
-from matplotlib.toolkits.basemap import Basemap
+from matplotlib.toolkits.basemap import Basemap, supported_projections
# 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.
-projection = 'lcc' # map projection
+projection = XX # map projection ('lcc','stere','laea','aea' etc)
+ # 'print supported_projections' gives a list
resolution = XX # resolution of boundaries ('c','l','i',or 'h')
-lon_0=XX # longitude of origin of map projection domain (degrees).
-lat_0=XX # standard parallel/latitude of origin of map projection domain.
+lon_0= XX # longitude of origin of map projection domain (degrees).
+lat_0= XX # standard parallel/latitude of origin of map projection domain.
width = XX # width of map projecton domain in km.
height = XX # height of map projection domain in km.
m = Basemap(lon_0=lon_0,lat_0=lat_0,\
Added: trunk/py4science/examples/skel/basemap3_skel.py
===================================================================
--- trunk/py4science/examples/skel/basemap3_skel.py
(rev 0)
+++ trunk/py4science/examples/skel/basemap3_skel.py 2007-11-23 13:38:18 UTC
(rev 4424)
@@ -0,0 +1,46 @@
+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)
+# lat/lon and name of location 1.
+lat1 = XX
+lon1 = XX
+name1 = XX
+# ditto for location 2.
+lat2 = XX
+lon2 = XX
+name2 = XX
+# convert these points to map projection coordinates
+# (using __call__ method of Basemap instance)
+x1, y1 = m(lon1, lat1)
+x2, y2 = m(lon2, lat2)
+# plot black dots at the two points.
+# make sure dots are drawn on top of other plot elements (zorder=10)
+m.scatter([x1,x2],[y1,y2],25,color='k',marker='o',zorder=10)
+# connect the dots along a great circle.
+m.drawgreatcircle(lon1,lat1,lon2,lat2,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(x1-100000,y1+100000,name1,fontsize=12,\
+ color='k',horizontalalignment='right',fontweight='bold')
+pylab.text(x2-100000,y2+100000,name2,fontsize=12,\
+ color='k',horizontalalignment='right',fontweight='bold')
+m.drawcoastlines(linewidth=0.5)
+m.fillcontinents(color='coral')
+m.drawcountries()
+m.drawstates()
+pylab.title(name1+' to '+name2+' Great Circle')
+pylab.show()
Added: trunk/py4science/examples/skel/basemap4_skel.py
===================================================================
--- trunk/py4science/examples/skel/basemap4_skel.py
(rev 0)
+++ trunk/py4science/examples/skel/basemap4_skel.py 2007-11-23 13:38:18 UTC
(rev 4424)
@@ -0,0 +1,35 @@
+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()
+# draw and label parallels.
+# labels is list of 4 values (default [0,0,0,0]) that control whether
+# parallels are labelled where they intersect the left, right, top or
+# bottom of the plot. For example labels=[1,0,0,1] will cause parallels
+# to be labelled where they intersect the left and bottom of the plot,
+# but not the right and top.
+labels = XX
+parallels = XX # a sequence of latitudes values
+m.drawparallels(parallels,labels=labels)
+# draw and label meridians.
+labels = XX
+meridians = XX # a sequence of longitude values
+m.drawmeridians(meridians,labels=labels)
+pylab.title('labelled meridians and parallels',y=1.075)
+pylab.show()
Added: trunk/py4science/examples/skel/basemap5_skel.py
===================================================================
--- trunk/py4science/examples/skel/basemap5_skel.py
(rev 0)
+++ trunk/py4science/examples/skel/basemap5_skel.py 2007-11-23 13:38:18 UTC
(rev 4424)
@@ -0,0 +1,45 @@
+from matplotlib.toolkits.basemap import Basemap, NetCDFFile, cm
+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
+# Basemap comes with extra colormaps from Generic Mapping Tools
+# (imported as cm, pylab colormaps in pylab.cm)
+cmap = XX
+# set so masked values in an image will be painted specified color
+# (i.e. continents will be painted this color)
+color = XX
+cmap.set_bad(color)
+# create Basemap instance for mollweide projection.
+projection = XX # try moll, robin, sinu or ortho.
+# coastlines not used, so resolution set to None to skip
+# continent processing (this speeds things up a bit)
+m = Basemap(projection=projection,lon_0=lon_0,lat_0=lat_0,resolution=None)
+# 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)
+# draw parallels and meridians, but don't bother labelling them.
+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.show()
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