Revision: 7098
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7098&view=rev
Author:   leejjoon
Date:     2009-05-12 04:12:07 +0000 (Tue, 12 May 2009)

Log Message:
-----------
aspect for log-log plot

Modified Paths:
--------------
    trunk/matplotlib/CHANGELOG
    trunk/matplotlib/lib/matplotlib/axes.py

Added Paths:
-----------
    trunk/matplotlib/examples/pylab_examples/aspect_loglog.py

Modified: trunk/matplotlib/CHANGELOG
===================================================================
--- trunk/matplotlib/CHANGELOG  2009-05-08 19:04:34 UTC (rev 7097)
+++ trunk/matplotlib/CHANGELOG  2009-05-12 04:12:07 UTC (rev 7098)
@@ -1,4 +1,6 @@
 ======================================================================
+2009-05-11 aspect=1 in log-log plot gives square decades.
+
 2009-05-08 clabel takes new kwarg, rightside_up; if False, labels
            will not be flipped to keep them rightside-up.  This
            allows the use of clabel to make streamfunction arrows,

Added: trunk/matplotlib/examples/pylab_examples/aspect_loglog.py
===================================================================
--- trunk/matplotlib/examples/pylab_examples/aspect_loglog.py                   
        (rev 0)
+++ trunk/matplotlib/examples/pylab_examples/aspect_loglog.py   2009-05-12 
04:12:07 UTC (rev 7098)
@@ -0,0 +1,22 @@
+import matplotlib.pyplot as plt
+
+ax1 = plt.subplot(121)
+ax1.set_xscale("log")
+ax1.set_yscale("log")
+ax1.set_xlim(1e1, 1e3)
+ax1.set_ylim(1e2, 1e3)
+ax1.set_aspect(1)
+ax1.set_title("adjustable = box")
+
+ax2 = plt.subplot(122)
+ax2.set_xscale("log")
+ax2.set_yscale("log")
+ax2.set_adjustable("datalim")
+ax2.plot([1,3, 10], [1, 9, 100], "o-")
+ax2.set_xlim(1e-1, 1e2)
+ax2.set_ylim(1e-1, 1e3)
+ax2.set_aspect(1)
+ax2.set_title("adjustable = datalim")
+
+plt.draw()
+plt.show()

Modified: trunk/matplotlib/lib/matplotlib/axes.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/axes.py     2009-05-08 19:04:34 UTC (rev 
7097)
+++ trunk/matplotlib/lib/matplotlib/axes.py     2009-05-12 04:12:07 UTC (rev 
7098)
@@ -1085,7 +1085,7 @@
             raise ValueError('argument must be among %s' %
                                 ', '.join(mtransforms.BBox.coefs.keys()))
 
-    def get_data_ratio(self):
+    def get_data_ratio(self, mode="linear"):
         """
         Returns the aspect ratio of the raw data.
 
@@ -1093,11 +1093,18 @@
         types.
         """
         xmin,xmax = self.get_xbound()
-        xsize = max(math.fabs(xmax-xmin), 1e-30)
         ymin,ymax = self.get_ybound()
-        ysize = max(math.fabs(ymax-ymin), 1e-30)
+
+        if mode == "log":
+            xsize = max(math.fabs(math.log10(xmax)-math.log10(xmin)), 1e-30)
+            ysize = max(math.fabs(math.log10(ymax)-math.log10(ymin)), 1e-30)
+        else:
+            xsize = max(math.fabs(xmax-xmin), 1e-30)
+            ysize = max(math.fabs(ymax-ymin), 1e-30)
+
         return ysize/xsize
 
+
     def apply_aspect(self, position=None):
         '''
         Use :meth:`_aspect` and :meth:`_adjustable` to modify the
@@ -1106,7 +1113,20 @@
         if position is None:
             position = self.get_position(original=True)
 
+
         aspect = self.get_aspect()
+
+        xscale, yscale = self.get_xscale(), self.get_yscale()
+        if xscale == "linear" and yscale == "linear":
+            aspect_scale_mode = "linear"
+        elif xscale == "log" and yscale == "log":
+            aspect_scale_mode = "log"
+        else:
+            warnings.warn(
+                'aspect is not supported for Axes with xscale=%s, yscale=%s' \
+                % (xscale, yscale))
+            aspect = "auto"
+
         if aspect == 'auto':
             self.set_position( position , which='active')
             return
@@ -1127,7 +1147,7 @@
         figW,figH = self.get_figure().get_size_inches()
         fig_aspect = figH/figW
         if self._adjustable == 'box':
-            box_aspect = A * self.get_data_ratio()
+            box_aspect = A * self.get_data_ratio(mode=aspect_scale_mode)
             pb = position.frozen()
             pb1 = pb.shrunk_to_aspect(box_aspect, pb, fig_aspect)
             self.set_position(pb1.anchored(self.get_anchor(), pb), 'active')
@@ -1137,11 +1157,18 @@
         # by prior use of 'box'
         self.set_position(position, which='active')
 
+
         xmin,xmax = self.get_xbound()
+        ymin,ymax = self.get_ybound()
+
+        if aspect_scale_mode == "log":
+            xmin, xmax = math.log10(xmin), math.log10(xmax)
+            ymin, ymax = math.log10(ymin), math.log10(ymax)
+
         xsize = max(math.fabs(xmax-xmin), 1e-30)
-        ymin,ymax = self.get_ybound()
         ysize = max(math.fabs(ymax-ymin), 1e-30)
 
+
         l,b,w,h = position.bounds
         box_aspect = fig_aspect * (h/w)
         data_ratio = box_aspect / A
@@ -1152,9 +1179,18 @@
         if abs(y_expander) < 0.005:
             #print 'good enough already'
             return
-        dL = self.dataLim
-        xr = 1.05 * dL.width
-        yr = 1.05 * dL.height
+
+        if aspect_scale_mode == "log":
+            dL = self.dataLim
+            dL_width = math.log10(dL.x1) - math.log10(dL.x0)
+            dL_height = math.log10(dL.y1) - math.log10(dL.y0)
+            xr = 1.05 * dL_width
+            yr = 1.05 * dL_height
+        else:
+            dL = self.dataLim
+            xr = 1.05 * dL.width
+            yr = 1.05 * dL.height
+
         xmarg = xsize - xr
         ymarg = ysize - yr
         Ysize = data_ratio * xsize
@@ -1189,14 +1225,20 @@
             yc = 0.5*(ymin+ymax)
             y0 = yc - Ysize/2.0
             y1 = yc + Ysize/2.0
-            self.set_ybound((y0, y1))
+            if aspect_scale_mode == "log":
+                self.set_ybound((10.**y0, 10.**y1))
+            else:
+                self.set_ybound((y0, y1))
             #print 'New y0, y1:', y0, y1
             #print 'New ysize, ysize/xsize', y1-y0, (y1-y0)/xsize
         else:
             xc = 0.5*(xmin+xmax)
             x0 = xc - Xsize/2.0
             x1 = xc + Xsize/2.0
-            self.set_xbound((x0, x1))
+            if aspect_scale_mode == "log":
+                self.set_xbound((10.**x0, 10.**x1))
+            else:
+                self.set_xbound((x0, x1))
             #print 'New x0, x1:', x0, x1
             #print 'New xsize, ysize/xsize', x1-x0, ysize/(x1-x0)
 


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

------------------------------------------------------------------------------
The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your
production scanning environment may not be a perfect world - but thanks to
Kodak, there's a perfect scanner to get the job done! With the NEW KODAK i700
Series Scanner you'll get full speed at 300 dpi even with all image 
processing features enabled. http://p.sf.net/sfu/kodak-com
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to