def onpress(self, event): if event.canvas.toolbar.mode != '': return if event.inaxes is None: return self.lasso = Lasso(event.inaxes, (event.xdata, event.ydata), self.callback_generator(event))
def onpress(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)
def onpress(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) #mengunci hasil yang sudah didapatkan dari tarikan self.canvas.widgetlock(self.lasso)
def onpress(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)
def onpresslasso(self, event): ''' Create lasso when button pressed on active canvas/axes ''' # ensure that current dataset is active self.xys = self.parent.xys # row, column pixels list passed from plotter (parent) # axes, xys, callback (reverse x,y to match row, col of numpy ) self.lasso = Lasso(event.inaxes, (event.ydata, event.xdata), self.callbacklasso)
def onpress(self, event): if self.canvas.widgetlock.locked(): return if event.inaxes is None: return if event.key in ('escape', ): self.selected = [] self.lasso_callback([]) return # TODO: implement zoom out as undo. # zoom in to selection if event.key in ('+', '='): selected_rows = self.df.ix[self.selected] xs = selected_rows[self.xcol] ys = selected_rows[self.ycol] self.ax.set_xlim(xs.min(), xs.max()) self.ax.set_ylim(ys.min(), ys.max()) self.canvas.draw() return self.lasso = Lasso(event.inaxes, (event.xdata, event.ydata), self.lasso_callback) self.canvas.widgetlock(self.lasso) # acquire lock on lasso widget self.lasso_lock = True # used when we release
def onclick(self, event): if self.canvas.widgetlock.locked(): return if event.inaxes is None: return if event.button != 1: return self.lasso = Lasso(event.inaxes, (event.xdata, event.ydata), self.callback) self.canvas.widgetlock(self.lasso)
def __init__(self, ax, xy, callback=None, useblit=True, linecolor='black'): """a simple extension of the Lasso widget that allows you to specify the color of the line draw keywords) ax=axis to draw the lasso on xy=an x,y tuple with the location of the start callback=callback function to call on release of the lasso useblit=boolean i don't understand and am just passing through linecolor=a string denoting the matplotlib color designation of the lasso """ Lasso.__init__(self, ax, xy, callback, useblit) #these lines are basic rewrites of lines that existed in the original Lasso init function #which ultimately set self.line and make sure that self.line has been added to self.axis via add_line x, y = xy self.line = Line2D([x], [y], linestyle='-', color=linecolor, lw=2) self.axes.add_line(self.line)
def __init__(self, ax, xy, callback=None, useblit=True,linecolor='black'): """a simple extension of the Lasso widget that allows you to specify the color of the line draw keywords) ax=axis to draw the lasso on xy=an x,y tuple with the location of the start callback=callback function to call on release of the lasso useblit=boolean i don't understand and am just passing through linecolor=a string denoting the matplotlib color designation of the lasso """ Lasso.__init__(self,ax,xy,callback,useblit) #these lines are basic rewrites of lines that existed in the original Lasso init function #which ultimately set self.line and make sure that self.line has been added to self.axis via add_line x, y = xy self.line = Line2D([x],[y],linestyle='-', color=linecolor, lw=2) self.axes.add_line(self.line)
def onpresslasso(self, event): ''' Create lasso when button pressed on active canvas/axes ''' # ensure that current dataset is active print('onpress lasso called') self.xys = self.parent.xy # passed from plotter (parent) print('Length of xys is', len(self.xys)) self.lasso = Lasso(event.inaxes, (event.xdata, event.ydata), self.callbacklasso) # self.canvas.widgetlock(self.lasso) # skip... gives ValueError: already locked print('end of onpress lasso')
def onpress(self, event): print(event) if self.canvas.widgetlock.locked(): self.callback(None) return if event.inaxes is None: return self.current_axes = event.inaxes self.lasso = Lasso(event.inaxes, (event.xdata, event.ydata), self.callback) self.canvas.widgetlock(self.lasso)
def onpress(self, event): if self.canvas.widgetlock.locked(): return if event.inaxes is None: return if pyfusion.VERBOSE > 7: print event.xdata # left button is normal - right does lasso - but this seesm to hang - crash? ## if event.button == 1: self.canvas.button_press_event(event) self.lasso = Lasso(event.inaxes, (event.xdata, event.ydata), self.callback) # acquire a lock on the widget drawing self.canvas.widgetlock(self.lasso)
def onpress(self, event): '''called on button_press_event, runs Lasso with callback ''' 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)
def on_press(self, evt): if self.legend and self.legend.hit_test(evt): return if evt.button == 1: self.selection_key = evt.key if self.canvas.widgetlock.locked(): return if evt.inaxes is None: return if self.navtoolbar.get_mode() == 'lasso': self.lasso = Lasso(evt.inaxes, (evt.xdata, evt.ydata), self.lasso_callback) # acquire a lock on the widget drawing self.canvas.widgetlock(self.lasso)
def onpress(self, event): #print event.button if self.canvas.widgetlock.locked(): #print 'foo' self.canvas.widgetlock.release(self.lasso) #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)
def onpress(self, event): from matplotlib.widgets import Lasso if event.inaxes != self.image_axes: return if self.image_axes.figure.canvas.widgetlock.locked(): return self.focus_incr() self.selector = Lasso( event.inaxes, (event.xdata, event.ydata), self.update_line_from_verts ) self.image_axes.figure.canvas.widgetlock(self.selector)
def onpress(self, event): """ on press callback, will run lasso """ if event.inaxes != self.axes: return if len(self._next_select) > 0: if self.canvas.widgetlock.locked(): return self._lasso = Lasso(event.inaxes, (event.xdata, event.ydata), self.__lasso_callback__) # acquire a lock on the widget drawing self.canvas.widgetlock(self._lasso) self.pchanged()
def onpress(self, event): if self.canvas.widgetlock.locked(): return if event.inaxes is None: return # Remove the previous ROI, does somehow only work after drawing the new ROI is done if self.userROI is not None: self.userROI.remove() self.lasso = Lasso(event.inaxes, (event.xdata, event.ydata), self.callback) self.canvas.widgetlock( self.lasso) # acquire a lock on the widget drawing
def onpress(self, event): """ Button-press handler """ if self._mode == 'o': # Outline mode if self.fig.canvas.widgetlock.locked(): return if event.inaxes is not self.ax: return self.curr_lasso = Lasso(event.inaxes, (event.xdata, event.ydata), self.onlasso) # Set a lock on drawing the lasso until finished self.fig.canvas.widgetlock(self.curr_lasso) elif self._mode == 's': # Selection mode if event.inaxes is not self.ax: return curr_select = None for feat in self.state._features[self.frameIndex]: if feat.contains(event): curr_select = feat prev_select = self._curr_selection if curr_select is not None: if prev_select is not None: # TODO: Make a tracking association # TODO: May need some mapping of frameIndex to frameNum # This is only valid if I am able to see the previous # selection. This logic also makes it impossible to # have feat1 be the same object as feat2 if (prev_select.get_visible() and self.frameIndex != prev_select.frame): # We are making associations across frames! tmp = self.state.associate_features( prev_select, curr_select) if tmp is not None: self.ax.add_artist(tmp.obj) prev_select.deselect() if prev_select is curr_select: self._curr_selection = None else: self._curr_selection = curr_select curr_select.select() self.fig.canvas.draw_idle()
def on_press(self, evt): """canvas mousedown handler """ if evt.button == 1: if self.canvas.widgetlock.locked(): return if evt.inaxes is None: return if self.navtoolbar and self.navtoolbar.get_mode() == 'lasso': self.lasso = Lasso(evt.inaxes, (evt.xdata, evt.ydata), self.lasso_callback) self.canvas.widgetlock(self.lasso)
def startLasso(self, event): if event.button != 1: return if self.canvas.widgetlock.locked(): # sometimes there is a bug lassostop is not intercepted!!! # so to avoid 2 start self.clearArtistSelection() return if event.inaxes is None: return self.lasso = Lasso(event.inaxes, (event.xdata, event.ydata), self.stopLasso) # acquire a lock on the widget drawing self.canvas.widgetlock(self.lasso)
def _onPress(self, event): if self.canvas.widgetlock.locked(): return # Check if lasso is dragged onto another axes if event.inaxes <> self.viewer.ax: return # Create lasso self.lasso = Lasso(event.inaxes, (event.xdata, event.ydata), self._postLasso) if self.maskParams['selectorType'] == 'pen': self.lasso.line.set_linewidth(self.maskParams['width']) self.lasso.line.set_color((1, 0, 0)) # Acquire a lock on the widget drawing self.canvas.widgetlock(self.lasso)
def onbuttonpress(evt): if fig.canvas.widgetlock.locked(): return if evt.inaxes is None: return while len(selected) > 0: lines = selected.pop() for line in lines: evt.inaxes.lines.remove(line) altpicker[0] = evt.key == 'control' lasso = Lasso(evt.inaxes, (evt.xdata, evt.ydata), onlasso) lassos.append(lasso) fig.canvas.widgetlock(lasso)
def onpress(self, event): """ Callback function for connection to the event manager. """ from matplotlib.widgets import Lasso if event.inaxes != self.image_axes: return if self.image_axes.figure.canvas.widgetlock.locked(): return self.focus_incr() self.selector = Lasso( event.inaxes, (event.xdata, event.ydata), self.update_line_from_verts ) self.image_axes.figure.canvas.widgetlock(self.selector)
def startLasso(self, event): if event.button != 1: return #~ print 'startLasso', self.canvas.widgetlock.locked() if self.canvas.widgetlock.locked(): # sometimes there is a bug lassostop is not intercepted!!! # so to avoid 2 start #~ print 'in lasso bug' self.clearArtistSelection() return if event.inaxes is None: return #~ for e in self.toBeDisconnected: #~ self.canvas.mpl_disconnect(e) self.lasso = Lasso(event.inaxes, (event.xdata, event.ydata), self.stopLasso) # acquire a lock on the widget drawing self.canvas.widgetlock(self.lasso)
def on_left_mouse_down(event): if figure.canvas.widgetlock.locked(): return if event.inaxes != axes: return idx = tool_choice.GetSelection() tool = tool_choice.GetItemLabel(idx) if tool == TOOL_OUTLINE: lasso = Lasso(axes, (event.xdata, event.ydata), on_lasso) lasso.line.set_color('red') current_lasso.append(lasso) figure.canvas.widgetlock(lasso) elif tool == TOOL_ERASE: erase_label = labels[int(event.ydata), int(event.xdata)] if erase_label > 0: labels[labels == erase_label] = 0 labels[labels > erase_label] -= 1 draw() if labels.max() == 0: erase_all_button.Disable() erase_last_button.Disable()
def lasso_leftdown(self, event=None): """leftdown event handler for lasso mode""" try: self.report_leftdown(event=event) except: return if event.inaxes: # set lasso color color='goldenrod' cmap = getattr(self.conf, 'cmap', None) if isinstance(cmap, dict): cmap = cmap['int'] try: if cmap is not None: rgb = (int(i*255)^255 for i in cmap._lut[0][:3]) color = '#%02x%02x%02x' % tuple(rgb) except: pass self.lasso = Lasso(event.inaxes, (event.xdata, event.ydata), self.lassoHandler) self.lasso.line.set_color(color)
def _free_draw(self, event): self.lasso = Lasso(event.inaxes, (event.xdata, event.ydata), self._free_draw_callback) # acquire a lock on the widget drawing self.canvas.widgetlock(self.lasso)
def press_lasso(self, event, callback): if event.inaxes is None: return self.lasso_obj = Lasso( event.inaxes, (event.xdata, event.ydata), lambda verts: self.contains_points(verts, callback))
def _onPress(self, event): self.myEvent = event if event.inaxes is None: return self.lasso = Lasso(event.inaxes, (event.xdata, event.ydata), self.callback)
import matplotlib.pyplot as plt from matplotlib.widgets import Lasso x = range(0, 100) y = range(0, 100) fig, ax = plt.subplots() ax.plot(x, y) def printCoordinate(x): print(x) lso = Lasso(ax, (10, 10), printCoordinate) plt.show()