[Scipy-svn] r2676 - trunk/Lib/sandbox/timeseries/plotlib

scipy-svn at scipy.org scipy-svn at scipy.org
Fri Feb 2 23:19:08 EST 2007


Author: pierregm
Date: 2007-02-02 22:19:06 -0600 (Fri, 02 Feb 2007)
New Revision: 2676

Modified:
   trunk/Lib/sandbox/timeseries/plotlib/mpl_timeseries.py
Log:
mpl_timeseries: add nonsingular from matplotlib SVN

Modified: trunk/Lib/sandbox/timeseries/plotlib/mpl_timeseries.py
===================================================================
--- trunk/Lib/sandbox/timeseries/plotlib/mpl_timeseries.py	2007-02-03 03:21:30 UTC (rev 2675)
+++ trunk/Lib/sandbox/timeseries/plotlib/mpl_timeseries.py	2007-02-03 04:19:06 UTC (rev 2676)
@@ -27,7 +27,7 @@
 from matplotlib.ticker import Formatter, ScalarFormatter, FuncFormatter, \
                               Locator, FixedLocator
 
-from matplotlib.transforms import nonsingular
+#from matplotlib.transforms import nonsingular
 
 import numpy as N
 import maskedarray as MA
@@ -99,6 +99,33 @@
     figure_instance._seen[key] = a
     return a
 
+
+def nonsingular(vmin, vmax, expander=0.001, tiny=1e-15, increasing=True):
+    '''
+    Ensure the endpoints of a range are not too close together.
+
+    "too close" means the interval is smaller than 'tiny' times
+            the maximum absolute value.
+
+    If they are too close, each will be moved by the 'expander'.
+    If 'increasing' is True and vmin > vmax, they will be swapped.
+    '''
+    #TODO: Remove that when matplotlib incorporate it by default
+    swapped = False
+    if vmax < vmin:
+        vmin, vmax = vmax, vmin
+        swapped = True
+    if vmax - vmin <= max(abs(vmin), abs(vmax)) * tiny:
+        if vmin==0.0:
+            vmin = -expander
+            vmax = expander
+        else:
+            vmin -= expander*abs(vmin)
+            vmax += expander*abs(vmax)
+    if swapped and not increasing:
+        vmin, vmax = vmax, vmin
+    return vmin, vmax
+
 ##### -------------------------------------------------------------------------
 #---- --- Locators ---
 ##### -------------------------------------------------------------------------




More information about the Scipy-svn mailing list