On 07/21/2010 09:11 AM, Aman Thakral wrote: > Ok, so I've fixed it. Its just because the mouse goes outside the axes. > How do I make the change in the code? > > Error: line 924 in widgets.py > > old code: > > x,y = event.xdata, event.ydata > > fixed code: > > if not event.xdata is None: > x = event.xdata > else: > x = self.prev[0]
Good! When you make the svn diff, as requested by John, you might change to a more typical idiom--easier to read, to my eye at least: if event.xdata is None: x = self.prev[0] else: x = event.xdata Eric > > if not event.ydata is None: > y = event.ydata > else: > y = self.prev[1] > > I know it's a bit verbose, but it works. > > Thanks, > Aman > > On Wed, Jul 21, 2010 at 2:44 PM, Aman Thakral <aman.thak...@gmail.com > <mailto:aman.thak...@gmail.com>> wrote: > > Update on the error. > > It occurs in the following cases: > - User clicks and drags from left to right and approaches the edge > of the right side of the axes > - User clicks and drags from right to left and approaches the edge > of the left side of the axes > > I'm working on this bug now, I'll see if I can fix it. I'll welcome > any input you guys can provide though. > > Thanks, > Aman > > > On Wed, Jul 21, 2010 at 1:58 PM, Aman Thakral > <aman.thak...@gmail.com <mailto:aman.thak...@gmail.com>> wrote: > > Hi all, > > I'm getting the following exception when I use the Span > Selector. It happens when I try and select the entire region. > > Exception in Tkinter callback > > Traceback (most recent call last): > File "C:\Python26\lib\lib-tk\Tkinter.py", line 1410, in __call__ > return self.func(*args) > File > "C:\Python26\Lib\site-packages\matplotlib\backends\backend_tkagg.py", > line 246, in motion_notify_event > FigureCanvasBase.motion_notify_event(self, x, y, > guiEvent=event) > File > "C:\Python26\Lib\site-packages\matplotlib\backend_bases.py", > line 1245, in motion_notify_event > self.callbacks.process(s, event) > File "C:\Python26\Lib\site-packages\matplotlib\cbook.py", > line 165, in process > func(*args, **kwargs) > File "C:\Python26\Lib\site-packages\matplotlib\widgets.py", > line 952, in onmove > self.rect.set_width(maxv-minv) > TypeError: unsupported operand type(s) for -: 'float' and 'NoneType' > > > My sample code is shown here (its also attached): > > import matplotlib.pyplot as plt > from matplotlib.widgets import SpanSelector > import numpy as np > import datetime > > class TimeSelector(SpanSelector): > """ > SpanSelector that is only activated by the left mouse button > """ > def ignore(self,event): > if event.button == 2 or event.button == 3: return True > > def onselect(xmin,xmax): > print xmin,xmax > > fig = plt.figure() > ax = fig.add_subplot(111) > span = TimeSelector(ax, onselect, 'horizontal', useblit=True, > rectprops=dict(alpha=0.5, facecolor='yellow') ) > > y = np.random.rand(100,1) > start = datetime.datetime(2010,7,15,0,0) > x = [] > for i in range(len(y)): > x.append(start + datetime.timedelta(hours=i)) > > ax.plot_date(x,y,'b-') > plt.show() > > Any help on this issue would be greatly appreciated. > > Thanks, > Aman > > > > > -- > Aman Thakral > B.Eng & Biosci, M.Eng Design > > > > > -- > Aman Thakral > B.Eng & Biosci, M.Eng Design > > > > ------------------------------------------------------------------------------ > This SF.net email is sponsored by Sprint > What will you do first with EVO, the first 4G phone? > Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first > > > > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/matplotlib-users ------------------------------------------------------------------------------ This SF.net email is sponsored by Sprint What will you do first with EVO, the first 4G phone? Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users