Re: [matplotlib-devel] example: wx.ToolTip for MPL axes
Here's an updated version. mpl.use('WXAgg') should come before importing pylab. Martin Martin Spacek wrote: Not sure if this already exists, but here's an example file of how to get a wx.ToolTip to pop up and report the current mouse position in data coordinates over a MPL axes. Not sure if it's the best way of doing this, but it seems to work really well for me. Perhaps it would be useful to add this to the MPL examples? Cheers, Martin """Example of how to use wx tooltips on a matplotlib figure window. A tooltip pops up and tracks the mouse when the mouse is above the axes, updating it's value with the current x and y data values under mouse position""" import matplotlib as mpl mpl.use('WXAgg') mpl.interactive(False) import pylab as pl from pylab import get_current_fig_manager as gcfm import wx class wxToolTipExample(object): def __init__(self): self.f = pl.figure() self.a = self.f.add_subplot(111) self.tooltip = wx.ToolTip(tip='') # create an empty tooltip self.tooltip.SetDelay(500) # set popup delay in ms gcfm().canvas.SetToolTip(self.tooltip) # connect tooltip to canvas self.f.canvas.mpl_connect('motion_notify_event', self.onmotion) def onmotion(self, event): """Called during mouse motion over figure""" if event.xdata != None and event.ydata != None: self.tooltip.SetTip(tip='x=%f, y=%f' % (event.xdata, event.ydata)) example = wxToolTipExample() pl.show() - Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642___ Matplotlib-devel mailing list Matplotlib-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
Re: [matplotlib-devel] example: wx.ToolTip for MPL axes
And here's yet another refinement. Works around a wx bug (see http://article.gmane.org/gmane.comp.python.wxpython/37937/match=tooltip) that prevents newlines from being recognized in the tooltip string. Also, disables the tooltip when the mouse moves off of the axes, which prevents stray tooltips from hanging around. Martin Martin Spacek wrote: Here's an updated version. mpl.use('WXAgg') should come before importing pylab. Martin """Example of how to use wx tooltips on a matplotlib figure window. A tooltip pops up and tracks the mouse when the mouse is above the axes, updating it's value with the current x and y data values under mouse position""" import matplotlib as mpl mpl.use('WXAgg') mpl.interactive(False) import pylab as pl from pylab import get_current_fig_manager as gcfm import wx class wxToolTipExample(object): def __init__(self): self.f = pl.figure() self.a = self.f.add_subplot(111) self.tooltip = wx.ToolTip(tip='tip with a long %s line and a newline\n' % (' '*100)) # create a long tooltip with newline to get around wx bug where newlines aren't recognized on subsequent self.tooltip.SetTip() calls self.tooltip.Enable(False) # leave disabled for now self.tooltip.SetDelay(0) # set popup delay in ms gcfm().canvas.SetToolTip(self.tooltip) # connect the tooltip to the canvas self.f.canvas.mpl_connect('motion_notify_event', self.onmotion) def onmotion(self, event): """Called during mouse motion over figure""" if event.xdata != None and event.ydata != None: # mouse is inside the axes tip='x=%f\ny=%f' % (event.xdata, event.ydata) self.tooltip.SetTip(tip) # update the tooltip self.tooltip.Enable(True) # make sure it's enabled else: # mouse is outside the axes self.tooltip.Enable(False) # disable the tooltip example = wxToolTipExample() pl.show() - Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642___ Matplotlib-devel mailing list Matplotlib-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-devel