Revision: 3844
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3844&view=rev
Author:   jdh2358
Date:     2007-09-12 13:37:41 -0700 (Wed, 12 Sep 2007)

Log Message:
-----------
fixed a bar units bug

Modified Paths:
--------------
    trunk/matplotlib/API_CHANGES
    trunk/matplotlib/CHANGELOG
    trunk/matplotlib/lib/matplotlib/artist.py
    trunk/matplotlib/lib/matplotlib/axes.py
    trunk/matplotlib/lib/matplotlib/axis.py
    trunk/matplotlib/lib/matplotlib/mlab.py
    trunk/matplotlib/lib/matplotlib/patches.py

Added Paths:
-----------
    trunk/matplotlib/examples/units/bar_demo2.py

Modified: trunk/matplotlib/API_CHANGES
===================================================================
--- trunk/matplotlib/API_CHANGES        2007-09-12 20:25:17 UTC (rev 3843)
+++ trunk/matplotlib/API_CHANGES        2007-09-12 20:37:41 UTC (rev 3844)
@@ -1,3 +1,5 @@
+    Made skiprows=1 the default on csv2rec
+
     The gd and paint backends have been deleted.
 
     The errorbar method and function now accept additional kwargs

Modified: trunk/matplotlib/CHANGELOG
===================================================================
--- trunk/matplotlib/CHANGELOG  2007-09-12 20:25:17 UTC (rev 3843)
+++ trunk/matplotlib/CHANGELOG  2007-09-12 20:37:41 UTC (rev 3844)
@@ -1,3 +1,7 @@
+2007-09-12 Fixed a Axes.bar unit bug - JDH
+
+2007-09-10 Made skiprows=1 the default on csv2rec - JDH
+
 2007-09-09 Split out the plotting part of pylab and put it in
            pyplot.py; removed numerix from the remaining pylab.py,
            which imports everything from pyplot.py.  The intention

Added: trunk/matplotlib/examples/units/bar_demo2.py
===================================================================
--- trunk/matplotlib/examples/units/bar_demo2.py                                
(rev 0)
+++ trunk/matplotlib/examples/units/bar_demo2.py        2007-09-12 20:37:41 UTC 
(rev 3844)
@@ -0,0 +1,34 @@
+"""
+plot using a variety of cm vs inches conversions.  The example shows
+how default unit instrospection works (ax1), how various keywords can
+be used to set the x and y units to override the defaults (ax2, ax3,
+ax4) and how one can set the xlimits using scalars (ax3, current units
+assumed) or units (conversions applied to get the numbers to current
+units)
+
+"""
+from basic_units import cm, inch
+from pylab import figure, show, nx
+
+cms = cm *nx.arange(0, 10, 2)
+bottom=0*cm
+width=0.8*cm
+
+fig = figure()
+
+ax1 = fig.add_subplot(2,2,1)
+ax1.bar(cms, cms, bottom=bottom)
+
+ax2 = fig.add_subplot(2,2,2)
+ax2.bar(cms, cms, bottom=bottom, width=width, xunits=cm, yunits=inch)
+
+ax3 = fig.add_subplot(2,2,3)
+ax3.bar(cms, cms, bottom=bottom, width=width, xunits=inch, yunits=cm)
+ax3.set_xlim(3, 6)  # scalars are interpreted in current units
+
+ax4 = fig.add_subplot(2,2,4)
+ax4.bar(cms, cms, bottom=bottom, width=width, xunits=inch, yunits=inch)
+#fig.savefig('simple_conversion_plot.png')
+ax4.set_xlim(3*cm, 6*cm) # cm are converted to inches
+
+show()

Modified: trunk/matplotlib/lib/matplotlib/artist.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/artist.py   2007-09-12 20:25:17 UTC (rev 
3843)
+++ trunk/matplotlib/lib/matplotlib/artist.py   2007-09-12 20:37:41 UTC (rev 
3844)
@@ -51,7 +51,7 @@
         self._remove_method = None
 
     def remove(self):
-        '''
+        """
         Remove the artist from the figure if possible.  The effect will not
         be visible until the figure is redrawn, e.g., with ax.draw_idle().
         Call ax.relim() to update the axes limits if desired.
@@ -60,7 +60,7 @@
         was added to axes with autolim=True.
 
         Note: there is no support for removing the artist's legend entry.
-        '''
+        """
 
         # There is no method to set the callback.  Instead the parent should 
set
         # the _remove_method attribute directly.  This would be a protected

Modified: trunk/matplotlib/lib/matplotlib/axes.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/axes.py     2007-09-12 20:25:17 UTC (rev 
3843)
+++ trunk/matplotlib/lib/matplotlib/axes.py     2007-09-12 20:37:41 UTC (rev 
3844)
@@ -1198,23 +1198,27 @@
     def _process_unit_info(self, xdata=None, ydata=None, kwargs=None):
         'look for unit kwargs and update the axis instances as necessary'
 
-        if self.xaxis is None or self.xaxis is None: return
+        if self.xaxis is None or self.yaxis is None: return
 
-
+        #print 'processing', self.get_geometry()
         if xdata is not None:
             self.xaxis.update_units(xdata)
+            #print '\tset from xdata', self.xaxis.units
 
         if ydata is not None:
             self.yaxis.update_units(ydata)
+            #print '\tset from ydata', self.yaxis.units
 
         # process kwargs 2nd since these will override default units
         if kwargs is not None:
             xunits = kwargs.pop( 'xunits', self.xaxis.units)
             if xunits!=self.xaxis.units:
+                #print '\tkw setting xunits', xunits
                 self.xaxis.set_units(xunits)
 
             yunits = kwargs.pop('yunits', self.yaxis.units)
             if yunits!=self.yaxis.units:
+                #print '\tkw setting yunits', yunits
                 self.yaxis.set_units(yunits)
 
     def in_axes(self, xwin, ywin):
@@ -3114,11 +3118,13 @@
         else:
             raise ValueError, 'invalid orientation: %s' % orientation
 
-        left = npy.asarray(left)
-        height = npy.asarray(height)
-        width = npy.asarray(width)
-        bottom = npy.asarray(bottom)
 
+        # do not convert to array here as unit info is lost
+        #left = npy.asarray(left)
+        #height = npy.asarray(height)
+        #width = npy.asarray(width)
+        #bottom = npy.asarray(bottom)
+
         if len(linewidth) == 1: linewidth = linewidth * nbars
 
         # if color looks like a color string, an RGB tuple or a
@@ -3161,14 +3167,14 @@
         # lets do some conversions now
         if self.xaxis is not None:
             xconv = self.xaxis.converter
-            if ( xconv ):
+            if xconv is not None:
                 units = self.xaxis.get_units()
                 left = xconv.convert( left, units )
                 width = xconv.convert( width, units )
 
         if self.yaxis is not None:
             yconv = self.yaxis.converter
-            if ( yconv ):
+            if yconv is not None :
                 units = self.yaxis.get_units()
                 bottom = yconv.convert( bottom, units )
                 height = yconv.convert( height, units )
@@ -3208,12 +3214,14 @@
 
         if xerr is not None or yerr is not None:
             if orientation == 'vertical':
-                x = left + 0.5*width
-                y = bottom + height
+                # using list comps rather than arrays to preserve unit info
+                x = [l+0.5*w for l, w in zip(left, width)]
+                y = [b+h for b,h in zip(bottom, height)]
 
             elif orientation == 'horizontal':
-                x = left + width
-                y = bottom + 0.5*height
+                # using list comps rather than arrays to preserve unit info
+                x = [l+w for l,w in zip(left, width)]
+                y = [b+0.5*h for b,h in zip(bottom, height)]
 
             self.errorbar(
                 x, y,

Modified: trunk/matplotlib/lib/matplotlib/axis.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/axis.py     2007-09-12 20:25:17 UTC (rev 
3843)
+++ trunk/matplotlib/lib/matplotlib/axis.py     2007-09-12 20:37:41 UTC (rev 
3844)
@@ -828,7 +828,7 @@
             return x
 
         ret =  self.converter.convert(x, self.units)
-        #print 'convert_units converting: units=%s, converter=%s, in=%s, 
out=%s'%(self.units, self.converter, x, ret)
+        #print 'convert_units converting: axis=%s, units=%s, converter=%s, 
in=%s, out=%s'%(self, self.units, self.converter, x, ret)
         return ret
 
     def set_units(self, u):

Modified: trunk/matplotlib/lib/matplotlib/mlab.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/mlab.py     2007-09-12 20:25:17 UTC (rev 
3843)
+++ trunk/matplotlib/lib/matplotlib/mlab.py     2007-09-12 20:37:41 UTC (rev 
3844)
@@ -1253,9 +1253,9 @@
     if r==1 or c==1:
         X.shape = max(r,c),
     if unpack: return X.transpose()
-    return X
+    else: return X
 
-def csv2rec(fname, comments='#', skiprows=0, checkrows=5, delimiter=',',
+def csv2rec(fname, comments='#', skiprows=1, checkrows=5, delimiter=',',
             converterd=None, names=None, missing=None):
     """
     Load data from comma/space/tab delimited file in fname into a

Modified: trunk/matplotlib/lib/matplotlib/patches.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/patches.py  2007-09-12 20:25:17 UTC (rev 
3843)
+++ trunk/matplotlib/lib/matplotlib/patches.py  2007-09-12 20:37:41 UTC (rev 
3844)
@@ -77,6 +77,8 @@
         if len(kwargs): artist.setp(self, **kwargs)
     __init__.__doc__ = cbook.dedent(__init__.__doc__) % artist.kwdocd
 
+
+
     def contains(self, mouseevent):
         """Test whether the mouse event occurred in the patch.
 
@@ -347,7 +349,6 @@
         Return the vertices of the rectangle
         """
         x, y = self.xy
-
         left, right = self.convert_xunits((x, x + self.width))
         bottom, top = self.convert_yunits((y, y + self.height))
 


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
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to