Revision: 4061
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4061&view=rev
Author:   jdh2358
Date:     2007-10-29 11:52:41 -0700 (Mon, 29 Oct 2007)

Log Message:
-----------
fixed some examples bugs

Modified Paths:
--------------
    trunk/matplotlib/examples/keypress_demo.py
    trunk/matplotlib/examples/units/bar_unit_demo.py
    trunk/matplotlib/lib/matplotlib/axes.py
    trunk/matplotlib/lib/matplotlib/mlab.py
    trunk/matplotlib/lib/matplotlib/patches.py

Modified: trunk/matplotlib/examples/keypress_demo.py
===================================================================
--- trunk/matplotlib/examples/keypress_demo.py  2007-10-29 18:37:17 UTC (rev 
4060)
+++ trunk/matplotlib/examples/keypress_demo.py  2007-10-29 18:52:41 UTC (rev 
4061)
@@ -1,21 +1,23 @@
 #!/usr/bin/env python
 """
 Show how to connect to keypress events
-
-Note, on the wx backend on some platforms (eg linux), you have to
-first click on the figure before the keypress events are activated.
-If you know how to fix this, please email us!
 """
-from pylab import *
+import numpy as n
+from pylab import figure, show
 
 def press(event):
     print 'press', event.key
-    if event.key=='g':
-        grid()
-        draw()
+    if event.key=='x':
+        visible = xl.get_visible()
+        xl.set_visible(not visible)
+        fig.canvas.draw()
 
-connect('key_press_event', press)
+fig = figure()
+ax = fig.add_subplot(111)
 
-title('press g to toggle grid')
-plot(rand(12), rand(12), 'go')
+fig.canvas.mpl_connect('key_press_event', press)
+
+ax.plot(n.random.rand(12), n.random.rand(12), 'go')
+xl = ax.set_xlabel('easy come, easy go')
+
 show()

Modified: trunk/matplotlib/examples/units/bar_unit_demo.py
===================================================================
--- trunk/matplotlib/examples/units/bar_unit_demo.py    2007-10-29 18:37:17 UTC 
(rev 4060)
+++ trunk/matplotlib/examples/units/bar_unit_demo.py    2007-10-29 18:52:41 UTC 
(rev 4061)
@@ -4,15 +4,16 @@
 
 N = 5
 menMeans = (150*cm, 160*cm, 146*cm, 172*cm, 155*cm)
-menStd =   (20*cm, 30*cm, 32*cm, 10*cm, 20*cm)
+menStd =   ( 20*cm,  30*cm,  32*cm,  10*cm,  20*cm)
 
 fig = figure()
 ax = fig.add_subplot(111)
 
 ind = nx.arange(N)    # the x locations for the groups
-width = 0.35       # the width of the bars
+width = 0.35         # the width of the bars
 p1 = ax.bar(ind, menMeans, width, color='r', bottom=0*cm, yerr=menStd)
 
+
 womenMeans = (145*cm, 149*cm, 172*cm, 165*cm, 200*cm)
 womenStd =   (30*cm, 25*cm, 20*cm, 31*cm, 22*cm)
 p2 = ax.bar(ind+width, womenMeans, width, color='y', bottom=0*cm, 
yerr=womenStd)

Modified: trunk/matplotlib/lib/matplotlib/axes.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/axes.py     2007-10-29 18:37:17 UTC (rev 
4060)
+++ trunk/matplotlib/lib/matplotlib/axes.py     2007-10-29 18:52:41 UTC (rev 
4061)
@@ -1173,6 +1173,8 @@
         # Otherwise, it will compute the bounds of it's current data
         # and the data in xydata
         xys = npy.asarray(xys)
+        
+
         self.dataLim.update_numerix_xy(xys, -1)
 
 
@@ -3242,22 +3244,7 @@
 
         patches = []
 
-        # lets do some conversions now
-        if self.xaxis is not None:
-            xconv = self.xaxis.converter
-            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 is not None :
-                units = self.yaxis.get_units()
-                bottom = yconv.convert( bottom, units )
-                height = yconv.convert( height, units )
-
-
         if align == 'edge':
             pass
         elif align == 'center':
@@ -3645,23 +3632,24 @@
         a list of error bar cap lines, the third element is a list of
         line collections for the horizontal and vertical error ranges
         """
+
         self._process_unit_info(xdata=x, ydata=y, kwargs=kwargs)
         if not self._hold: self.cla()
 
-        # make sure all the args are iterable arrays
-        if not iterable(x): x = npy.array([x])
-        else: x = npy.asarray(x)
+        # make sure all the args are iterable; use lists not arrays to 
preserve units
+        if not iterable(x):
+            x = [x]
 
-        if not iterable(y): y = npy.array([y])
-        else: y = npy.asarray(y)
+        if not iterable(y):
+            y = [y]
 
         if xerr is not None:
-            if not iterable(xerr): xerr = npy.array([xerr])
-            else: xerr = npy.asarray(xerr)
+            if not iterable(xerr):
+                xerr = [xerr]
 
         if yerr is not None:
-            if not iterable(yerr): yerr = npy.array([yerr])
-            else: yerr = npy.asarray(yerr)
+            if not iterable(yerr):
+                yerr = [yerr]
 
         l0 = None
 
@@ -3677,7 +3665,9 @@
         if 'lw' in kwargs:
             lines_kw['lw']=kwargs['lw']
 
-        if not iterable(lolims): lolims = npy.array([lolims]*len(x), bool)
+        # arrays fine here, they are booleans and hence not units
+        if not iterable(lolims):
+            lolims = npy.asarray([lolims]*len(x), bool)
         else: lolims = npy.asarray(lolims, bool)
 
         if not iterable(uplims): uplims = npy.array([uplims]*len(x), bool)
@@ -3699,12 +3689,14 @@
                 plot_kw['mew']=kwargs['mew']
 
         if xerr is not None:
-            if len(xerr.shape) == 1:
-                left  = x-xerr
-                right = x+xerr
+            if iterable(xerr) and len(xerr)==2:
+                # using list comps rather than arrays to preserve units        
        
+                left  = [thisx-thiserr for (thisx, thiserr) in zip(x,xerr[0])]
+                right  = [thisx+thiserr for (thisx, thiserr) in zip(x,xerr[1])]
             else:
-                left  = x-xerr[0]
-                right = x+xerr[1]
+                # using list comps rather than arrays to preserve units
+                left  = [thisx-thiserr for (thisx, thiserr) in zip(x,xerr)]
+                right  = [thisx+thiserr for (thisx, thiserr) in zip(x,xerr)]
 
             barcols.append( self.hlines(y, left, right, **lines_kw ) )
             if capsize > 0:
@@ -3723,12 +3715,14 @@
                     caplines.extend( self.plot(right, y, 'k|', **plot_kw) )
 
         if yerr is not None:
-            if len(yerr.shape) == 1:
-                lower = y-yerr
-                upper = y+yerr
+            if iterable(yerr) and len(yerr)==2:
+                # using list comps rather than arrays to preserve units
+                lower  = [thisy-thiserr for (thisy, thiserr) in zip(y,yerr[0])]
+                upper  = [thisy+thiserr for (thisy, thiserr) in zip(y,yerr[1])]
             else:
-                lower = y-yerr[0]
-                upper = y+yerr[1]
+                # using list comps rather than arrays to preserve units
+                lower  = [thisy-thiserr for (thisy, thiserr) in zip(y,yerr)]
+                upper  = [thisy+thiserr for (thisy, thiserr) in zip(y,yerr)]
 
             barcols.append( self.vlines(x, lower, upper, **lines_kw) )
             if capsize > 0:

Modified: trunk/matplotlib/lib/matplotlib/mlab.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/mlab.py     2007-10-29 18:37:17 UTC (rev 
4060)
+++ trunk/matplotlib/lib/matplotlib/mlab.py     2007-10-29 18:52:41 UTC (rev 
4061)
@@ -1455,7 +1455,116 @@
     for row in r:
         writer.writerow(map(str, row))
     fh.close()
+    
+try:
+    import pyExcelerator as excel
+except ImportError:
+    pass
+else:
 
+    class Format:
+        xlstyle = None
+        def convert(self, x):
+            return x
+
+    class FormatFloat(Format):
+        def __init__(self, precision=4):
+            self.xlstyle = excel.XFStyle()
+            zeros = ''.join(['0']*precision)
+            self.xlstyle.num_format_str = '#,##0.%s;[RED]-#,##0.%s'%(zeros, 
zeros)
+
+    class FormatInt(Format):
+        convert = int
+        def __init__(self):
+
+            self.xlstyle = excel.XFStyle()
+            self.xlstyle.num_format_str = '#,##;[RED]-#,##'
+
+    class FormatPercent(Format):
+        def __init__(self, precision=4):
+            self.xlstyle = excel.XFStyle()
+            zeros = ''.join(['0']*precision)
+            self.xlstyle.num_format_str = '0.%s%;[RED]-0.%s%'%(zeros, zeros)
+
+    class FormatThousands(FormatFloat):
+        def __init__(self, precision=1):
+            FormatFloat.__init__(self, precision)
+
+        def convert(self, x):
+            return x/1e3
+
+    class FormatMillions(FormatFloat):
+        def __init__(self, precision=1):
+            FormatFloat.__init__(self, precision)
+
+        def convert(self, x):
+            return x/1e6
+
+    class FormatDate(Format):
+        def __init__(self, fmt='%Y-%m-%d'):
+            self.fmt = fmt
+
+        def convert(self, val):
+            return val.strftime(self.fmt)
+
+    class FormatDatetime(Format):
+        def __init__(self, fmt='%Y-%m-%d %H:%M:%S'):
+            self.fmt = fmt
+
+        def convert(self, val):
+            return val.strftime(self.fmt)
+
+    class FormatObject(Format):
+
+        def convert(self, x):
+            return str(x)
+
+    def rec2excel(ws, r, formatd=None, rownum=0):
+        """
+        save record array r to excel pyExcelerator worksheet ws
+        starting at rownum
+
+        formatd is a dictionary mapping dtype name -> Format instances
+        """
+
+        if formatd is None:
+            formatd = dict()
+
+        formats = []
+        for i, name in enumerate(r.dtype.names):
+            dt = r.dtype[name]
+            format = formatd.get(name)
+            if format is None:
+                format = rec2excel.formatd.get(dt.type, FormatObject())
+
+            ws.write(rownum, i, name)
+            formats.append(format)
+
+        rownum+=1
+
+        ind = npy.arange(len(r.dtype.names))
+        for row in r:
+            for i in ind:
+                val = row[i]
+                format = formats[i]
+                val = format.convert(val)
+                if format.xlstyle is None:
+                    ws.write(rownum, i, val)
+                else:
+                    ws.write(rownum, i, val, format.xlstyle)
+            rownum += 1
+    rec2excel.formatd = {
+            npy.int16 : FormatInt(),                
+            npy.int32 : FormatInt(),
+            npy.int64 : FormatInt(),        
+            npy.float32 : FormatFloat(),
+            npy.float64 : FormatFloat(),        
+            npy.object_ : FormatObject(),
+            npy.string_ : Format(),        
+            }
+
+
+
 # some record array helpers
 def rec_append_field(rec, name, arr, dtype=None):
     'return a new record array with field name populated with data from array 
arr'

Modified: trunk/matplotlib/lib/matplotlib/patches.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/patches.py  2007-10-29 18:37:17 UTC (rev 
4060)
+++ trunk/matplotlib/lib/matplotlib/patches.py  2007-10-29 18:52:41 UTC (rev 
4061)
@@ -350,8 +350,10 @@
         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))
+        left = self.convert_xunits(x)
+        right = self.convert_xunits(x + self.width)
+        bottom = self.convert_yunits(y)
+        top = self.convert_yunits(y+self.height)
 
         return ( (left, bottom), (left, top),
                  (right, top), (right, bottom),
@@ -806,8 +808,15 @@
     def get_verts(self):
 
         xcenter, ycenter = self.center
+        width, height = self.width, self.height
 
-        width, height = self.width, self.height
+        xcenter = self.convert_xunits(xcenter)
+        width = self.convert_xunits(width)        
+        ycenter = self.convert_yunits(ycenter)
+        height = self.convert_xunits(height)        
+
+
+
         angle = self.angle
 
         theta = npy.arange(0.0, 360.0, 1.0)*npy.pi/180.0
@@ -820,8 +829,6 @@
             [npy.sin(rtheta), npy.cos(rtheta)],
             ])
 
-        x = self.convert_xunits(x)
-        y = self.convert_yunits(y)
 
         x, y = npy.dot(R, npy.array([x, y]))
         x += xcenter
@@ -857,6 +864,8 @@
         x, y = self.center
         x = self.convert_xunits(x)
         y = self.convert_yunits(y)
+        w = self.convert_xunits(self.width)/2.
+        h = self.convert_yunits(self.height)/2.
 
         theta = self.angle * npy.pi/180.
         T = npy.array([
@@ -864,10 +873,8 @@
             [0, 1, y],
             [0, 0, 1]])
 
-        w, h = self.width/2, self.height/2.
-        w = self.convert_xunits(w)
-        h = self.convert_yunits(h)
 
+
         
         S = npy.array([
             [w, 0, 0],


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: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Matplotlib-checkins mailing list
Matplotlib-checkins@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to