RectangleSelector Issue

I am having a little issue with the matplotlib.widgets RectangleSelector. The behavior is that the first time I try to select a region, no rectangle draws. All subsequent uses work correctly.

Here is how I am calling:
if self.zoomMode:
if self.canvas.widgetlock.locked():
self.canvas.widgetlock.release( self.lasso )

        RectangleSelector( [self.ax](http://self.ax),
                           self._zoom_callback,
                           drawtype='box',
                           minspanx=5, minspany=5,
                           spancoords='pixels' )

else:
if self.canvas.widgetlock.locked():
self.canvas.widgetlock.release( self.lasso )

        if event.inaxes is None: return
           
        self.lasso = Lasso( event.inaxes,
                            ( event.xdata, event.ydata ),
                            self._selection_callback )
        self.canvas.widgetlock( self.lasso )

I have attempted to debug this behavior. If I breakpoint at the call to RectangleSelector and then step in, selection works as-expected on the first call. However, if I move the breakpoint into the callback, it does not work correctly on the first call and the breakpoint is not reached. Again, all subsequent uses work correctly.

Any thoughts?
I am using 0.99.1.1 on Ubuntu 10.04
Linux martin-laptop 2.6.32-25-generic #45-Ubuntu SMP Sat Oct 16 19:52:42 UTC 2010 x86_64 GNU/Linux
‘/usr/lib/pymodules/python2.6/matplotlib/init.pyc’

Thanks.
martin.

This could be another instance of a problem resulting from our changes
to how references are taken for callbacks. Try saving the
RectangleSelector you create (I'm just guessing here):

             self.rs = RectangleSelector( self.ax,
                                self._zoom_callback,
                                drawtype='box',
                                minspanx=5, minspany=5,
                                spancoords='pixels' )

Ryan

···

On Thu, Nov 11, 2010 at 9:41 PM, Martin Bures <needemesleepe@...287...> wrote:

I am having a little issue with the matplotlib.widgets RectangleSelector.
The behavior is that the first time I try to select a region, no rectangle
draws. All subsequent uses work correctly.

Here is how I am calling:
if self.zoomMode:
if self.canvas.widgetlock.locked():
self.canvas.widgetlock.release( self.lasso )

        RectangleSelector\( self\.ax,
                           self\.\_zoom\_callback,
                           drawtype=&#39;box&#39;,
                           minspanx=5, minspany=5,
                           spancoords=&#39;pixels&#39; \)

else:
if self.canvas.widgetlock.locked():
self.canvas.widgetlock.release( self.lasso )

        if event\.inaxes is None: return

        self\.lasso = Lasso\( event\.inaxes,
                            \( event\.xdata, event\.ydata \),
                            self\.\_selection\_callback \)
        self\.canvas\.widgetlock\( self\.lasso \)

--
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma

I noticed that in another post and did try that but the behavior was the same.

martin.

···

On Fri, Nov 12, 2010 at 9:14 AM, Ryan May <rmay31@…287…> wrote:

On Thu, Nov 11, 2010 at 9:41 PM, Martin Bures <needemesleepe@…287…> wrote:

I am having a little issue with the matplotlib.widgets RectangleSelector.

The behavior is that the first time I try to select a region, no rectangle

draws. All subsequent uses work correctly.

Here is how I am calling:

if self.zoomMode:

        if self.canvas.widgetlock.locked():
            self.canvas.widgetlock.release( self.lasso )
        RectangleSelector( [self.ax](http://self.ax),
                           self._zoom_callback,
                           drawtype='box',
                           minspanx=5, minspany=5,
                           spancoords='pixels' )

else:

        if self.canvas.widgetlock.locked():
            self.canvas.widgetlock.release( self.lasso )
        if event.inaxes is None: return
        self.lasso = Lasso( event.inaxes,
                            ( event.xdata, event.ydata ),
                            self._selection_callback )
        self.canvas.widgetlock( self.lasso )

This could be another instance of a problem resulting from our changes

to how references are taken for callbacks. Try saving the

RectangleSelector you create (I’m just guessing here):

         [self.rs](http://self.rs) = RectangleSelector( [self.ax](http://self.ax),

self._zoom_callback,

                            drawtype='box',

                            minspanx=5, minspany=5,

                            spancoords='pixels' )

Ryan

Ryan May

Graduate Research Assistant

School of Meteorology

University of Oklahoma