I am writing a wx / matplotlib application and am having significant difficulties adding a new tool to the matplotlib navigation bar.
Basically, I want to add selection tools (marquee, lasso, etc.) that will switch in subnet mode with controlled meannesses. At the moment, I could not find any functions that would allow me to do this easily.
However, I just discovered this function, which would look like it would be useful: http://matplotlib.sourceforge.net/api/axes_api.html?highlight=set_navigate_mode#matplotlib.axes.Axes.set_navigate_mode
Unfortunately, as follows from the warning, this really does not help me.
Does anyone know how to do this? Below is a stripped-down example showing how far I got. The bookmark icon is used instead of the lasso icon, and I have reduced the functionality of the lasso for short.
import wx from matplotlib.patches import Rectangle from matplotlib.widgets import Lasso from matplotlib.figure import Figure from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg from matplotlib.backends.backend_wxagg import NavigationToolbar2WxAgg as NavigationToolbar class ScatterPanel(FigureCanvasWxAgg): ''' Contains the guts for drawing scatter plots. ''' def __init__(self, parent, **kwargs): self.figure = Figure() FigureCanvasWxAgg.__init__(self, parent, -1, self.figure, **kwargs) self.canvas = self.figure.canvas self.SetMinSize((100,100)) self.figure.set_facecolor((1,1,1)) self.figure.set_edgecolor((1,1,1)) self.canvas.SetBackgroundColour('white') self.subplot = self.figure.add_subplot(111) self.navtoolbar = None self.lasso = None self.redraw() self.canvas.mpl_connect('button_press_event', self.on_press) self.canvas.mpl_connect('button_release_event', self.on_release) def lasso_callback(self, verts): pass def on_press(self, evt): if evt.button == 1: if self.canvas.widgetlock.locked(): return if evt.inaxes is None: return if self.navtoolbar.mode == 'lasso': self.lasso = Lasso(evt.inaxes, (evt.xdata, evt.ydata), self.lasso_callback) self.canvas.widgetlock(self.lasso) def on_release(self, evt):
Thanks Adam
python matplotlib toolbar
Adam fraser
source share