show annotations only on hovering

Gregor Thalhammer wrote:

I didn't understand what you mean by 'plot nodes'

the markers, sorry

, but there exist
figure_enter_event, figure_leave_event, axes_enter_event and
axes_leave_event, see

http://matplotlib.sourceforge.net/examples/event_handling/figure_axes_enter_leave.html

first of all: why these *_enter_event and *_leave_event aren't in
http://matplotlib.sourceforge.net/api/backend_bases_api.html#matplotlib.backend_bases.FigureCanvasBase.mpl_connect

second: they are cool, but I need to be more specific: I want to show some
annotations only if I move my mouse pointer over a marker, and to make them
disappear when I move my mouse pointer away (something like
http://www.scipy.org/Cookbook/Matplotlib/Interactive_Plotting, but on mouse
hovering)

···

--
By ZeD

This is just a doc oversight – I’ll fix it.

I think your solution is the right way to do it with the exiting mpl infrastructure, though one could use the “blit” api to make it a little more efficient to redraw just the needed artists rather than the whole figure each time (doing this would further complicate the code). Since you call your approach “ugly, and conceptually wrong”, perhaps you can sketch what you think the right interface should be for something like this, and we will see if there is anything we can do within the existing mpl infrastructure to make it easier.

FYI, check out the canvas.onHilite implementation, which shows how to use a hover to highlight individual artists (title, axes, xlabel, ylabel, ticklabel etc). This problem is a little
easier, since what you are doing is triggering an action on artist B when artist A is hovered over.

import numpy as np
import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(np.random.rand(10))
ax.set_title('hover over me')
ax.set_xlabel('or me')

ax.set_ylabel('or me')
ax.grid()
fig.canvas.mpl_connect('motion_notify_event', fig.canvas.onHilite)

plt.show()

JDH

JDH

···

On Wed, Apr 15, 2009 at 8:03 AM, Vito De Tullio <zak.mc.kraken@…1348…> wrote:

Gregor Thalhammer wrote:

I didn’t understand what you mean by ‘plot nodes’

the markers, sorry

, but there exist

figure_enter_event, figure_leave_event, axes_enter_event and

axes_leave_event, see

http://matplotlib.sourceforge.net/examples/event_handling/figure_axes_enter_leave.html

first of all: why these *_enter_event and *_leave_event aren’t in

http://matplotlib.sourceforge.net/api/backend_bases_api.html#matplotlib.backend_bases.FigureCanvasBase.mpl_connect