SF.net SVN: matplotlib: [4992] trunk/toolkits/basemap

2008-03-04 Thread jswhit
Revision: 4992
  http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4992&view=rev
Author:   jswhit
Date: 2008-03-04 13:59:45 -0800 (Tue, 04 Mar 2008)

Log Message:
---
added drawmapscale method.

Modified Paths:
--
trunk/toolkits/basemap/Changelog
trunk/toolkits/basemap/README
trunk/toolkits/basemap/lib/mpl_toolkits/basemap/basemap.py

Modified: trunk/toolkits/basemap/Changelog
===
--- trunk/toolkits/basemap/Changelog2008-02-29 14:04:48 UTC (rev 4991)
+++ trunk/toolkits/basemap/Changelog2008-03-04 21:59:45 UTC (rev 4992)
@@ -1,4 +1,6 @@
 version 0.99
+   * added drawmapscale method to create a map scale bar similar
+ to that available with the GMT's psbasemap.
* Now lives in mpl_toolkits.basemap.  Instead
  of 'from matplotlib.toolkits.basemap import Basemap',
  use 'from mpl_toolkits.basemap import Basemap'.

Modified: trunk/toolkits/basemap/README
===
--- trunk/toolkits/basemap/README   2008-02-29 14:04:48 UTC (rev 4991)
+++ trunk/toolkits/basemap/README   2008-03-04 21:59:45 UTC (rev 4992)
@@ -114,5 +114,6 @@
 Scott Sinclair
 Ivan Lima
 Erik Andersen
+Michael Hearne
 
 for valuable contributions.

Modified: trunk/toolkits/basemap/lib/mpl_toolkits/basemap/basemap.py
===
--- trunk/toolkits/basemap/lib/mpl_toolkits/basemap/basemap.py  2008-02-29 
14:04:48 UTC (rev 4991)
+++ trunk/toolkits/basemap/lib/mpl_toolkits/basemap/basemap.py  2008-03-04 
21:59:45 UTC (rev 4992)
@@ -2768,6 +2768,176 @@
 im = self.imshow(self._bm_rgba,ax=ax)
 return im
 
+def drawmapscale(self,lon,lat,lon0,lat0,length,barstyle='simple',\
+ units='km',fontsize=9,yoffset=None,labelstyle='simple',\
+ fontcolor='k',fillcolor1='w',fillcolor2='k',ax=None):
+"""
+draw a map scale at lon,lat representing distance in the map
+projection coordinates at lon0,lat0. The length of the scale
+is specified by the length argument, with units given by the units
+keyword (default 'km').  Two styles of scale bar are available
+(specified by the labelstyle keyword) - 'simple' and 'fancy', which
+correspond roughly to the corresponding styles provided by 
+the Generic Mapping Tools software. Default is 'simple'.
+
+The fontsize and color of the map scale annotations can be specified
+with the fontsize (default 9) and fontcolor (default black) keywords.
+
+labelstyle='simple' results in basic annotation (the units on top
+of the scalebar and the distance below).  This is the default.
+If labelstyle='fancy' the map scale factor (ratio between
+the actual distance and map projection distance at lon0,lat0) and
+the value of lon0,lat0 are also printed on top of the scale bar.
+
+yoffset controls how tall the scale bar is, and how far the annotations
+are offset from the scale bar.  Default is 0.02 times the height of 
the map
+(0.02*(self.ymax-self.ymin)).
+
+fillcolor1 and fillcolor2 are only relevant for the 'fancy' scale bar.
+They are the colors of the alternating filled regions (default white
+and black).
+"""
+# get current axes instance (if none specified).
+if ax is None and self.ax is None:
+try:
+ax = pylab.gca()
+except:
+import pylab
+ax = pylab.gca()
+elif ax is None and self.ax is not None:
+ax = self.ax
+# not valid for cylindrical projection
+if self.projection == 'cyl':
+raise ValueError("cannot draw map scale for projection='cyl'")
+# convert length to meters
+if units == 'km':
+lenlab = length
+length = length*1000 
+elif units == 'mi':
+lenlab = length
+length = length*1609.344
+elif units == 'nmi':
+lenlab = length
+length = length*1852
+else:
+msg = "units must be 'km' (kilometers), "\
+"'mi' (miles) or 'nmi' (nautical miles)"
+raise KeyError(msg)
+# reference point and center of scale.
+x0,y0 = self(lon0,lat0)
+xc,yc = self(lon,lat)
+# make sure lon_0 between -180 and 180
+lon_0 = ((lon0+360) % 360) - 360
+if lat0>0:
+if lon>0:
+lonlatstr = u'%g\N{DEGREE SIGN}N, %g\N{DEGREE SIGN}E' % 
(lat0,lon_0)
+elif lon<0:
+lonlatstr = u'%g\N{DEGREE SIGN}N, %g\N{DEGREE SIGN}W' % 
(lat0,lon_0)
+else:
+lonlatstr = u'%g\N{DEGREE SIGN}, %g\N{DEGREE SIGN}W' % 
(lat0,lon_0)
+else:
+if lon>

SF.net SVN: matplotlib: [4993] trunk/toolkits/basemap/examples/ortho_demo. py

2008-03-04 Thread jswhit
Revision: 4993
  http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4993&view=rev
Author:   jswhit
Date: 2008-03-04 14:11:10 -0800 (Tue, 04 Mar 2008)

Log Message:
---
add a map scale.

Modified Paths:
--
trunk/toolkits/basemap/examples/ortho_demo.py

Modified: trunk/toolkits/basemap/examples/ortho_demo.py
===
--- trunk/toolkits/basemap/examples/ortho_demo.py   2008-03-04 21:59:45 UTC 
(rev 4992)
+++ trunk/toolkits/basemap/examples/ortho_demo.py   2008-03-04 22:11:10 UTC 
(rev 4993)
@@ -29,5 +29,11 @@
 m.drawparallels(arange(-90.,120.,30.))
 m.drawmeridians(arange(0.,420.,60.))
 m.drawmapboundary(fill_color='aqua')
+# add a map scale.
+length = 5000 
+x1,y1 = 0.2*m.xmax, 0.2*m.ymax
+lon1,lat1 = m(x1,y1,inverse=True)
+m.drawmapscale(lon1,lat1,lon_0,lat_0,length,fontsize=8,barstyle='fancy',\
+   labelstyle='fancy',units='km')
 title('Orthographic Map Centered on Lon=%s, Lat=%s' % (lon_0,lat_0))
 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 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins


SF.net SVN: matplotlib: [4994] trunk/toolkits/basemap/lib/mpl_toolkits/ basemap/basemap.py

2008-03-04 Thread jswhit
Revision: 4994
  http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4994&view=rev
Author:   jswhit
Date: 2008-03-04 14:58:49 -0800 (Tue, 04 Mar 2008)

Log Message:
---
update docstring for drawmapscale

Modified Paths:
--
trunk/toolkits/basemap/lib/mpl_toolkits/basemap/basemap.py

Modified: trunk/toolkits/basemap/lib/mpl_toolkits/basemap/basemap.py
===
--- trunk/toolkits/basemap/lib/mpl_toolkits/basemap/basemap.py  2008-03-04 
22:11:10 UTC (rev 4993)
+++ trunk/toolkits/basemap/lib/mpl_toolkits/basemap/basemap.py  2008-03-04 
22:58:49 UTC (rev 4994)
@@ -2796,6 +2796,8 @@
 fillcolor1 and fillcolor2 are only relevant for the 'fancy' scale bar.
 They are the colors of the alternating filled regions (default white
 and black).
+
+extra keyword 'ax' can be used to override the default axis instance.
 """
 # get current axes instance (if none specified).
 if ax is None and self.ax is None:


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 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins