Revision: 3895
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3895&view=rev
Author:   mdboom
Date:     2007-09-26 06:53:53 -0700 (Wed, 26 Sep 2007)

Log Message:
-----------
Fix log limits.  For minor speed improvements.

Modified Paths:
--------------
    branches/transforms/lib/matplotlib/axes.py
    branches/transforms/lib/matplotlib/axis.py
    branches/transforms/lib/matplotlib/lines.py
    branches/transforms/lib/matplotlib/scale.py
    branches/transforms/lib/matplotlib/ticker.py
    branches/transforms/lib/matplotlib/transforms.py

Modified: branches/transforms/lib/matplotlib/axes.py
===================================================================
--- branches/transforms/lib/matplotlib/axes.py  2007-09-26 13:41:15 UTC (rev 
3894)
+++ branches/transforms/lib/matplotlib/axes.py  2007-09-26 13:53:53 UTC (rev 
3895)
@@ -1095,18 +1095,9 @@
         line._remove_method = lambda h: self.lines.remove(h)
 
     def _update_line_limits(self, line):
-        xdata = line.get_xdata(orig=False)
-        ydata = line.get_ydata(orig=False)
+        xydata = line.get_xydata()
+        self.update_datalim( xydata )
 
-        if line.get_transform() != self.transData:
-            xys = self._get_verts_in_data_coords(
-                line.get_transform(), zip(xdata, ydata))
-            xdata = npy.array([x for x,y in xys])
-            ydata = npy.array([y for x,y in xys])
-
-        self.update_datalim_numerix( xdata, ydata )
-
-
     def add_patch(self, p):
         """
         Add a patch to the list of Axes patches; the clipbox will be
@@ -1151,7 +1142,6 @@
         xys = npy.asarray(xys)
         self.update_datalim_numerix(xys[:, 0], xys[:, 1])
 
-
     def update_datalim_numerix(self, x, y):
         'Update the data lim bbox with seq of xy tups'
         # if no data is set currently, the bbox will ignore it's

Modified: branches/transforms/lib/matplotlib/axis.py
===================================================================
--- branches/transforms/lib/matplotlib/axis.py  2007-09-26 13:41:15 UTC (rev 
3894)
+++ branches/transforms/lib/matplotlib/axis.py  2007-09-26 13:53:53 UTC (rev 
3895)
@@ -334,6 +334,9 @@
         'return the Interval instance for this axis view limits'
         return self.axes.viewLim.intervalx
 
+    def get_minpos(self):
+        return self.axes.dataLim.minposx
+    
     def get_data_interval(self):
         'return the Interval instance for this axis data limits'
         return self.axes.dataLim.intervalx
@@ -458,6 +461,9 @@
         'return the Interval instance for this axis view limits'
         return self.axes.viewLim.intervaly
 
+    def get_minpos(self):
+        return self.axes.dataLim.minposy
+    
     def get_data_interval(self):
         'return the Interval instance for this axis data limits'
         return self.axes.dataLim.intervaly
@@ -518,7 +524,13 @@
     def get_scale(self):
         return self._scale.name
     
-    def set_scale(self, value, base=10, subs=None):
+    def set_scale(self, value, basex=10, subsx=None, basey=10, subsy=None):
+        if self.axis_name == 'x':
+            base = basex
+            subs = subsx
+        else:
+            base = basey
+            subs = subsy
         # MGDTODO: Move these settings (ticker etc.) into the scale class 
itself
         value = value.lower()
         assert value.lower() in ('log', 'linear')
@@ -534,7 +546,7 @@
             self.set_minor_locator(LogLocator(base,subs))
             # MGDTODO: Pass base along
             self._scale = LogScale()
-            miny, maxy = getattr(self.axes.viewLim, 'interval' + self.axis)
+            miny, maxy = getattr(self.axes.viewLim, 'interval' + 
self.axis_name)
             if min(miny, maxy)<=0:
                 self.axes.autoscale_view()
                 
@@ -980,7 +992,7 @@
 
 class XAxis(Axis):
     __name__ = 'xaxis'
-    axis = 'x'
+    axis_name = 'x'
             
     def contains(self,mouseevent):
         """Test whether the mouse event occured in the x axis.
@@ -1156,6 +1168,9 @@
         'return the Interval instance for this axis view limits'
         return self.axes.viewLim.intervalx
 
+    def get_minpos(self):
+        return self.axes.dataLim.minposx
+    
     def get_data_interval(self):
         'return the Interval instance for this axis data limits'
         return self.axes.dataLim.intervalx
@@ -1163,7 +1178,7 @@
 
 class YAxis(Axis):
     __name__ = 'yaxis'
-    axis = 'y'
+    axis_name = 'y'
             
     def contains(self,mouseevent):
         """Test whether the mouse event occurred in the y axis.
@@ -1357,6 +1372,9 @@
         'return the Interval instance for this axis view limits'
         return self.axes.viewLim.intervaly
 
+    def get_minpos(self):
+        return self.axes.dataLim.minposy
+    
     def get_data_interval(self):
         'return the Interval instance for this axis data limits'
         return self.axes.dataLim.intervaly

Modified: branches/transforms/lib/matplotlib/lines.py
===================================================================
--- branches/transforms/lib/matplotlib/lines.py 2007-09-26 13:41:15 UTC (rev 
3894)
+++ branches/transforms/lib/matplotlib/lines.py 2007-09-26 13:53:53 UTC (rev 
3895)
@@ -564,6 +564,9 @@
             return self._yorig
         return self._y
 
+    def get_xydata(self):
+        return self._xy
+    
     def set_antialiased(self, b):
         """
         True if line should be drawin with antialiased rendering

Modified: branches/transforms/lib/matplotlib/scale.py
===================================================================
--- branches/transforms/lib/matplotlib/scale.py 2007-09-26 13:41:15 UTC (rev 
3894)
+++ branches/transforms/lib/matplotlib/scale.py 2007-09-26 13:53:53 UTC (rev 
3895)
@@ -13,6 +13,66 @@
         return IdentityTransform()
         
 class LogScale(ScaleBase):
+    class Log10Transform(Transform):
+        input_dims = 1
+        output_dims = 1
+        def __init__(self):
+            Transform.__init__(self)
+
+        def is_separable(self):
+            return True
+            
+        def transform(self, a):
+            return ma.log10(ma.masked_where(a <= 0.0, a * 10.0))
+            
+        def inverted(self):
+            return LogScale.InvertedLog10Transform()
+
+    class InvertedLog10Transform(Transform):
+        input_dims = 1
+        output_dims = 1
+        def __init__(self):
+            Transform.__init__(self)
+
+        def is_separable(self):
+            return True
+            
+        def transform(self, a):
+            return ma.power(10.0, a) / 10.0
+
+        def inverted(self):
+            return LogScale.Log10Transform()
+
+    class Log2Transform(Transform):
+        input_dims = 1
+        output_dims = 1
+        def __init__(self):
+            Transform.__init__(self)
+
+        def is_separable(self):
+            return True
+            
+        def transform(self, a):
+            return ma.log2(ma.masked_where(a <= 0.0, a * 2.0))
+            
+        def inverted(self):
+            return LogScale.InvertedLog2Transform()
+
+    class InvertedLog2Transform(Transform):
+        input_dims = 1
+        output_dims = 1
+        def __init__(self):
+            Transform.__init__(self)
+
+        def is_separable(self):
+            return True
+            
+        def transform(self, a):
+            return ma.power(2.0, a) / 2.0
+
+        def inverted(self):
+            return LogScale.Log2Transform()
+
     class LogTransform(Transform):
         input_dims = 1
         output_dims = 1
@@ -26,12 +86,12 @@
         def transform(self, a):
             if len(a) > 10:
                 print "Log Transforming..."
-            return ma.log10(ma.masked_where(a <= 0.0, a * 10.0))
+            return ma.log(ma.masked_where(a <= 0.0, a * self._base)) / 
npy.log(self._base)
             
         def inverted(self):
             return LogScale.InvertedLogTransform(self._base)
 
-    class InvertedLogTransform(Transform):
+    class InvertedLog2Transform(Transform):
         input_dims = 1
         output_dims = 1
         def __init__(self, base):
@@ -42,14 +102,21 @@
             return True
             
         def transform(self, a):
-            return ma.power(10.0, a) / 10.0
+            return ma.power(self._base, a) / self._base
 
         def inverted(self):
             return LogScale.LogTransform(self._base)
+        
+        
+    def __init__(self, base=10):
+        if base == 10.0:
+            self._transform = self.Log10Transform()
+        elif base == 2.0:
+            self._transform = self.Log2Transform()
+        # MGDTODO: Natural log etc.
+        else:
+            self._transform = self.LogTransform(base)
             
-    def __init__(self, base=10):
-        self._transform = self.LogTransform(base)
-
     def get_transform(self):
         return self._transform
 

Modified: branches/transforms/lib/matplotlib/ticker.py
===================================================================
--- branches/transforms/lib/matplotlib/ticker.py        2007-09-26 13:41:15 UTC 
(rev 3894)
+++ branches/transforms/lib/matplotlib/ticker.py        2007-09-26 13:53:53 UTC 
(rev 3895)
@@ -919,21 +919,21 @@
 
     def autoscale(self):
         'Try to choose the view limits intelligently'
-        vmin, vmax = self.axis.get_view_interval()
+        vmin, vmax = self.axis.get_data_interval()
         if vmax<vmin:
             vmin, vmax = vmax, vmin
 
-#         minpos = self.dataInterval.minpos()
+        minpos = self.axis.get_minpos()
 
-#         if minpos<=0:
-#             raise RuntimeError('No positive data to plot')
+        if minpos<=0:
+            raise RuntimeError('No positive data to plot')
 
-        # MGDTODO: Find a good way to track minpos
-        if vmin <= 0.0:
-            vmin = 0.1
-            
+        if vmin <= minpos:
+            vmin = minpos
+
         if not is_decade(vmin,self._base): vmin = decade_down(vmin,self._base)
         if not is_decade(vmax,self._base): vmax = decade_up(vmax,self._base)
+
         if vmin==vmax:
             vmin = decade_down(vmin,self._base)
             vmax = decade_up(vmax,self._base)

Modified: branches/transforms/lib/matplotlib/transforms.py
===================================================================
--- branches/transforms/lib/matplotlib/transforms.py    2007-09-26 13:41:15 UTC 
(rev 3894)
+++ branches/transforms/lib/matplotlib/transforms.py    2007-09-26 13:53:53 UTC 
(rev 3895)
@@ -224,6 +224,7 @@
     def __init__(self, points):
         BboxBase.__init__(self)
         self._points = npy.asarray(points, npy.float_)
+        self._minpos = npy.array([0.0000001, 0.0000001])
         self._invalid = False
 
     [EMAIL PROTECTED]
@@ -252,15 +253,22 @@
         return result
     
     def update_from_data(self, x, y, ignore=True):
-       if ignore:
+        if ignore:
+            self._points = npy.array(
+                [[x.min(), y.min()], [x.max(), y.max()]],
+                npy.float_)
+            self._minpos = npy.array(
+                [npy.where(x > 0.0, x, npy.inf).min(), npy.where(y > 0.0, y, 
npy.inf).min()],
+                npy.float_)
+        else:
            self._points = npy.array(
-               [[x.min(), y.min()], [x.max(), y.max()]],
-               npy.float_)
-       else:
-           self._points = npy.array(
                [[min(x.min(), self.xmin), min(y.min(), self.ymin)],
                 [max(x.max(), self.xmax), max(y.max(), self.ymax)]],
                 npy.float_)
+            minpos = npy.array(
+                [npy.where(x > 0.0, x, npy.inf).min(), npy.where(y > 0.0, y, 
npy.inf).min()],
+                npy.float_)
+            self._minpos = npy.minimum(minpos, self._minpos)
         self.invalidate()
         
     def _set_xmin(self, val):
@@ -309,6 +317,18 @@
         self.invalidate()
     bounds = property(BboxBase._get_bounds, _set_bounds)
 
+    def _get_minpos(self):
+        return self._minpos
+    minpos = property(_get_minpos)
+
+    def _get_minposx(self):
+        return self._minpos[0]
+    minposx = property(_get_minposx)
+
+    def _get_minposy(self):
+        return self._minpos[1]
+    minposy = property(_get_minposy)
+    
     def get_points(self):
         self._invalid = False
         return self._points
@@ -541,7 +561,7 @@
 #             print "".join(traceback.format_stack())
 #             print points
         mtx = self.get_matrix()
-        points = npy.asarray(values, npy.float_)
+        # points = npy.asarray(values, npy.float_)
         return points * mtx[0,0] + mtx[0,1]
 
     transform_affine = transform
@@ -695,10 +715,15 @@
 #             print "".join(traceback.format_stack())
 #             print points
         mtx = self.get_matrix()
-        points = npy.asarray(points, npy.float_)
-        points = points.transpose()
-        points = npy.dot(mtx[0:2, 0:2], points)
-        points = points + mtx[0:2, 2:]
+        if ma.isarray(points):
+            points = points.transpose()
+            points = ma.dot(mtx[0:2, 0:2], points)
+            points = points + mtx[0:2, 2:]
+        else:
+            points = npy.asarray(points, npy.float_)
+            points = points.transpose()
+            points = npy.dot(mtx[0:2, 0:2], points)
+            points = points + mtx[0:2, 2:]
         return points.transpose()
 
     transform_affine = transform
@@ -869,7 +894,7 @@
             y_points = y.transform(points[:, 1])
             y_points = y_points.reshape((len(y_points), 1))
 
-        return npy.concatenate((x_points, y_points), 1)
+        return ma.concatenate((x_points, y_points), 1)
     transform_non_affine = transform
     
     def transform_affine(self, points):


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
Matplotlib-checkins@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to