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

Reply via email to