Revision: 7003
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7003&view=rev
Author:   jdh2358
Date:     2009-03-24 01:49:18 +0000 (Tue, 24 Mar 2009)

Log Message:
-----------
added prune option to maxnlocataor; updated finance demo

Modified Paths:
--------------
    trunk/matplotlib/examples/pylab_examples/finance_work2.py
    trunk/matplotlib/lib/matplotlib/ticker.py

Modified: trunk/matplotlib/examples/pylab_examples/finance_work2.py
===================================================================
--- trunk/matplotlib/examples/pylab_examples/finance_work2.py   2009-03-23 
19:18:35 UTC (rev 7002)
+++ trunk/matplotlib/examples/pylab_examples/finance_work2.py   2009-03-24 
01:49:18 UTC (rev 7003)
@@ -201,7 +201,7 @@
 ax3.text(0.025, 0.95, 'MACD (%d, %d, %d)'%(nfast, nslow, nema), va='top',
          transform=ax3.transAxes, fontsize=textsize)
 
-ax3.set_yticks([])
+#ax3.set_yticks([])
 # turn off upper axis tick labels, rotate the lower ones, etc
 for ax in ax1, ax2, ax2t, ax3:
     if ax!=ax3:
@@ -215,15 +215,11 @@
     ax.fmt_xdata = mdates.DateFormatter('%Y-%m-%d')
 
 
-class PriceFormatter(mticker.FormatStrFormatter):
-    'suppress the lowest tick label to prevent overlap'
-    def __call__(self, x, pos=None):
-        if pos==0:
-            return ''
-        else:
-            return mticker.FormatStrFormatter.__call__(self, x, pos=None)
-ax2.yaxis.set_major_formatter(PriceFormatter('%d'))
 
+# at most 5 ticks, pruning the upper and lower so they don't overlap
+# with other ticks
+ax2.yaxis.set_major_locator(mticker.MaxNLocator(5, prune='both'))
+ax3.yaxis.set_major_locator(mticker.MaxNLocator(5, prune='both'))
 plt.show()
 
 

Modified: trunk/matplotlib/lib/matplotlib/ticker.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/ticker.py   2009-03-23 19:18:35 UTC (rev 
7002)
+++ trunk/matplotlib/lib/matplotlib/ticker.py   2009-03-24 01:49:18 UTC (rev 
7003)
@@ -913,13 +913,27 @@
     """
 
     def __init__(self, nbins = 10, steps = None,
-                                trim = True,
-                                integer=False,
-                                symmetric=False):
+                 trim = True,
+                 integer=False,
+                 symmetric=False,
+                 prune=None):
+        """
+        Keyword args:
+        *prune*
+            Remove edge ticks -- useful for stacked or ganed plots
+            where the upper tick of one axes overlaps with the lower
+            tick of the axes above it.  one of 'lower' | 'upper'|
+            'both' | None.  If prune=='lower', the smallest tick will
+            be removed.  If prune=='upper', the largest tick will be
+            removed.  If prune=='both', the largest and smallest ticks
+            will be removed.  If prune==None, no ticks will be removed
+
+        """
         self._nbins = int(nbins)
         self._trim = trim
         self._integer = integer
         self._symmetric = symmetric
+        self._prune = prune
         if steps is None:
             self._steps = [1, 1.5, 2, 2.5, 3, 4, 5, 6, 8, 10]
         else:
@@ -957,7 +971,16 @@
     def __call__(self):
         vmin, vmax = self.axis.get_view_interval()
         vmin, vmax = mtransforms.nonsingular(vmin, vmax, expander = 0.05)
-        return self.bin_boundaries(vmin, vmax)
+        locs = self.bin_boundaries(vmin, vmax)
+        #print 'locs=', locs
+        prune = self._prune
+        if prune=='lower':
+            locs = locs[1:]
+        elif prune=='upper':
+            locs = locs[:-1]
+        elif prune=='both':
+            locs = locs[1:-1]
+        return locs
 
     def view_limits(self, dmin, dmax):
         if self._symmetric:


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to