Skip to content

Lasso

LassoManager

Source code in itfit/data_selectors/lasso.py
class LassoManager:
    """
    """
    def __init__(self, app, data: DataSelection):
        """Creates a lasso selector and applies the selection to the given data.

        Parameters:
            app (Fitter):
                Main application.
            data (DataSelection): 
                Data to apply selection.
        """
        self.app = app
        self.axes = app.ax
        self.canvas = self.axes.figure.canvas
        self.data = data

        self.Nxy = len(data.xdata)

        self.data.select_all()

        self.data.select_none()

        self.data_ploted = self.axes.plot(
            data.xdata, data.ydata, color=(0, 0, 0, 0))

        self.cid = self.canvas.mpl_connect('button_press_event', self.on_press)

        self.data.create_selected_poly(self.axes)

    def callback(self, verts):
        p = path.Path(verts)
        ind = p.contains_points(self.data.get_data())

        self.data.bool_selection(ind)
        self.delete()

    def delete(self):
        if hasattr(self, "lasso"):
            self.canvas.draw_idle()
            self.canvas.widgetlock.release(self.lasso)
            del self.lasso
        plt.disconnect(self.cid)
        self.cid = None

    def on_press(self, event):
        if self.canvas.widgetlock.locked():
            return
        if event.inaxes is None:
            return
        self.lasso = Lasso(event.inaxes,
                           (event.xdata, event.ydata),
                           self.callback)
        # acquire a lock on the widget drawing
        self.canvas.widgetlock(self.lasso)

__init__(app, data)

Creates a lasso selector and applies the selection to the given data.

Parameters:

Name Type Description Default
app Fitter

Main application.

required
data DataSelection

Data to apply selection.

required
Source code in itfit/data_selectors/lasso.py
def __init__(self, app, data: DataSelection):
    """Creates a lasso selector and applies the selection to the given data.

    Parameters:
        app (Fitter):
            Main application.
        data (DataSelection): 
            Data to apply selection.
    """
    self.app = app
    self.axes = app.ax
    self.canvas = self.axes.figure.canvas
    self.data = data

    self.Nxy = len(data.xdata)

    self.data.select_all()

    self.data.select_none()

    self.data_ploted = self.axes.plot(
        data.xdata, data.ydata, color=(0, 0, 0, 0))

    self.cid = self.canvas.mpl_connect('button_press_event', self.on_press)

    self.data.create_selected_poly(self.axes)

LassoTool

Bases: ToolToggleBase

Toggles Lasso Tool.

Source code in itfit/data_selectors/lasso.py
class LassoTool(ToolToggleBase):
    """Toggles Lasso Tool."""
    # default_keymap = ''
    description = 'Lasso me please'

    def __init__(self, *args, app, data: DataSelection, **kwargs):
        """Creates a lasso tool.

        Parameters:
            app (Fitter): 
                Main application.
            data (DataSelection): 
                Data to apply selection.
        """
        self.app = app
        self.data = data
        super().__init__(*args, **kwargs)

    def enable(self, *args):
        """Enables the lasso tool. Interaction is locked until mouse button is released.
        """
        self.lasso_manager = LassoManager(self.app, self.data)

    def disable(self, *args):
        """Disables the lasso tool. After tool unselect or data selection applied.
        """
        self.lasso_manager.delete()

__init__(*args, app, data, **kwargs)

Creates a lasso tool.

Parameters:

Name Type Description Default
app Fitter

Main application.

required
data DataSelection

Data to apply selection.

required
Source code in itfit/data_selectors/lasso.py
def __init__(self, *args, app, data: DataSelection, **kwargs):
    """Creates a lasso tool.

    Parameters:
        app (Fitter): 
            Main application.
        data (DataSelection): 
            Data to apply selection.
    """
    self.app = app
    self.data = data
    super().__init__(*args, **kwargs)

disable(*args)

Disables the lasso tool. After tool unselect or data selection applied.

Source code in itfit/data_selectors/lasso.py
def disable(self, *args):
    """Disables the lasso tool. After tool unselect or data selection applied.
    """
    self.lasso_manager.delete()

enable(*args)

Enables the lasso tool. Interaction is locked until mouse button is released.

Source code in itfit/data_selectors/lasso.py
def enable(self, *args):
    """Enables the lasso tool. Interaction is locked until mouse button is released.
    """
    self.lasso_manager = LassoManager(self.app, self.data)