Revision: 4312
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4312&view=rev
Author:   jswhit
Date:     2007-11-15 10:13:04 -0800 (Thu, 15 Nov 2007)

Log Message:
-----------
new customticks.py example.

Modified Paths:
--------------
    trunk/toolkits/basemap-testing/examples/README

Added Paths:
-----------
    trunk/toolkits/basemap-testing/examples/customticks.py

Modified: trunk/toolkits/basemap-testing/examples/README
===================================================================
--- trunk/toolkits/basemap-testing/examples/README      2007-11-15 18:10:54 UTC 
(rev 4311)
+++ trunk/toolkits/basemap-testing/examples/README      2007-11-15 18:13:04 UTC 
(rev 4312)
@@ -10,6 +10,9 @@
 
 contour_demo.py demonstrates the use of filled contours with map projections.
 
+customticks.py shows how to create custom tick labels for a cylindrical
+projection.
+
 plotmap.py is the example on the matplotlib 'screenshots' page (included
 in test.py) which shows the ETOPO topography as an image on a Lambert
 Conformal projection (using imshow).

Added: trunk/toolkits/basemap-testing/examples/customticks.py
===================================================================
--- trunk/toolkits/basemap-testing/examples/customticks.py                      
        (rev 0)
+++ trunk/toolkits/basemap-testing/examples/customticks.py      2007-11-15 
18:13:04 UTC (rev 4312)
@@ -0,0 +1,48 @@
+from matplotlib.toolkits.basemap import Basemap
+import pylab, numpy
+from matplotlib.ticker import FuncFormatter
+
+# example showing how to create custom tick labels for a cylindrical
+# projection.
+
+def deg2str(deg, dir='E', fmt="%3.1f"):
+    min = 60 * (deg - numpy.floor(deg))
+    deg = numpy.floor(deg)
+    if deg < 0:
+        if min != 0.0:
+            deg += 1.0
+            min -= 60.0
+        if dir=='E':
+            dir='W'
+        if dir=='N':
+            dir='S'
+    return (u"%d\N{DEGREE SIGN}" + fmt + "' %s") % (numpy.abs(deg), 
numpy.abs(min), dir)
+
+# create figure.
+fig=pylab.figure()
+# background color will be used for 'wet' areas.
+fig.add_axes([0.1,0.1,0.8,0.8],axisbg='aqua')
+# create Basemap instance (regular lat/lon projection).
+# suppress_ticks=False allows custom axes ticks to be used
+# Ticks are suppressed by default, so Basemap methods
+# drawparallels and drawmeridians used to draw labelled lat/lon grid.
+m = Basemap(llcrnrlon=-156.5,llcrnrlat=18.75,urcrnrlon=-154.5,urcrnrlat=20.5,
+            resolution='h',projection='cyl',suppress_ticks=False)
+# draw coastlines, fill land areas.
+m.drawcoastlines()
+m.fillcontinents(color="coral")
+# get axes instance.
+ax = pylab.gca()
+# add custom ticks.
+# This only works for projection='cyl'.
+def xformat(x, pos=None): return deg2str(x, 'E', fmt="%2.0f")
+xformatter = FuncFormatter(xformat)
+ax.xaxis.set_major_formatter(xformatter)
+def yformat(y, pos=None): return deg2str(y, 'N', fmt="%2.0f")
+yformatter = FuncFormatter(yformat)
+ax.yaxis.set_major_formatter(yformatter)
+ax.fmt_xdata = lambda x: deg2str(x, 'E', fmt="%5.3f")
+ax.fmt_ydata = lambda y: deg2str(y, 'N', fmt="%5.3f")
+ax.grid()
+ax.set_title('Hawaii')
+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: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to