|
From: <jd...@us...> - 2007-09-20 14:13:53
|
Revision: 3867
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3867&view=rev
Author: jdh2358
Date: 2007-09-20 07:13:51 -0700 (Thu, 20 Sep 2007)
Log Message:
-----------
committed rectangle selector lock patch
Modified Paths:
--------------
trunk/matplotlib/lib/matplotlib/mlab.py
trunk/matplotlib/lib/matplotlib/widgets.py
Modified: trunk/matplotlib/lib/matplotlib/mlab.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/mlab.py 2007-09-20 13:59:15 UTC (rev 3866)
+++ trunk/matplotlib/lib/matplotlib/mlab.py 2007-09-20 14:13:51 UTC (rev 3867)
@@ -1255,7 +1255,7 @@
if unpack: return X.transpose()
else: return X
-def csv2rec(fname, comments='#', skiprows=1, checkrows=5, delimiter=',',
+def csv2rec(fname, comments='#', skiprows=0, checkrows=5, delimiter=',',
converterd=None, names=None, missing=None):
"""
Load data from comma/space/tab delimited file in fname into a
@@ -1314,6 +1314,14 @@
else: return get_func(item, funcmap[func]) # recurse
else: return func
+
+ # map column names that clash with builtins -- TODO - extend this list
+ itemd = {
+ 'return' : 'return_',
+ 'file' : 'file_',
+ 'print' : 'print_',
+ }
+
def get_converters(reader):
converters = None
@@ -1352,6 +1360,7 @@
if not len(item):
item = 'column%d'%i
+ item = itemd.get(item, item)
cnt = seen.get(item, 0)
if cnt>0:
names.append(item + '%d'%cnt)
Modified: trunk/matplotlib/lib/matplotlib/widgets.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/widgets.py 2007-09-20 13:59:15 UTC (rev 3866)
+++ trunk/matplotlib/lib/matplotlib/widgets.py 2007-09-20 14:13:51 UTC (rev 3867)
@@ -955,24 +955,40 @@
warnings.warn('Use SpanSelector instead!', DeprecationWarning)
SpanSelector.__init__(self, ax, onselect, 'horizontal', **kwargs)
+
class RectangleSelector:
"""
Select a min/max range of the x axes for a matplotlib Axes
Example usage:
- ax = subplot(111)
- ax.plot(x,y)
+ from matplotlib.widgets import RectangleSelector
+ from pylab import *
- def onselect(eclick, erelease):
+ def onselect(eclick, erelease):
'eclick and erelease are matplotlib events at press and release'
- print 'startposition : (%f,%f)'%(eclick.xdata, eclick.ydata)
- print 'endposition : (%f,%f)'%(erelease.xdata, erelease.ydata)
- print 'used button : ', eclick.button
+ print ' startposition : (%f, %f)' % (eclick.xdata, eclick.ydata)
+ print ' endposition : (%f, %f)' % (erelease.xdata, erelease.ydata)
+ print ' used button : ', eclick.button
- span = Selector(ax, onselect,drawtype='box')
- show()
+ def toggle_Selector(event):
+ print ' Key pressed.'
+ if event.key in ['Q', 'q'] and toggle_Selector.RS.active:
+ print ' RectangleSelector deactivated.'
+ toggle_Selector.RS.set_active(False)
+ if event.key in ['A', 'a'] and not toggle_Selector.RS.active:
+ print ' RectangleSelector activated.'
+ toggle_Selector.RS.set_active(True)
+ x = arange(100)/(99.0)
+ y = sin(x)
+ fig = figure
+ ax = subplot(111)
+ ax.plot(x,y)
+
+ toggle_Selector.RS = RectangleSelector(ax, onselect, drawtype='line')
+ connect('key_press_event', toggle_Selector)
+ show()
"""
def __init__(self, ax, onselect, drawtype='box',
minspanx=None, minspany=None, useblit=False,
@@ -1001,8 +1017,6 @@
Use type if you want the mouse to draw a line, a box or nothing
between click and actual position ny setting
drawtype = 'line', drawtype='box' or drawtype = 'none'.
-
-
"""
self.ax = ax
self.visible = True
@@ -1012,6 +1026,7 @@
self.canvas.mpl_connect('button_release_event', self.release)
self.canvas.mpl_connect('draw_event', self.update_background)
+ self.active = True # for activation / deactivation
self.to_draw = None
self.background = None
@@ -1052,6 +1067,14 @@
def ignore(self, event):
'return True if event should be ignored'
+ # If RectangleSelector is not active :
+ if not self.active:
+ return True
+
+ # If canvas was locked
+ if not self.canvas.widgetlock.available(self):
+ return True
+
# If no button was pressed yet ignore the event if it was out
# of the axes
if self.eventpress == None:
@@ -1142,6 +1165,17 @@
self.update()
return False
+ def set_active(self, active):
+ """ Use this to activate / deactivate the RectangleSelector
+
+ from your program with an boolean variable 'active'.
+ """
+ self.active = active
+
+ def get_active(self):
+ """ to get status of active mode (boolean variable)"""
+ return self.active
+
class Lasso(Widget):
def __init__(self, ax, xy, callback=None, useblit=True):
self.axes = ax
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|