Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

matplotlib multiple connections to an event handler?

import sys
import matplotlib
import matplotlib.pyplot as plt
print matplotlib.__version__, matplotlib.get_backend()

def hit(event):
  sys.stderr.write('hit\n')

fig = plt.figure()
cid0 = fig.canvas.mpl_connect('key_press_event', hit)
cid1 = fig.canvas.mpl_connect('button_press_event', hit)
print cid0, cid1
plt.show()

With the code above, why can't I have both mouse press event and key press events firing hit? It seems in the order above only the key press events work, whereas if I swap the lines 10 and 11 around (order cid0 and cid1 assignment), then only the mouse events work. I.e. whichever one I connected first hogs the event handler. Is this a built in limitation of matplotlib, or am I trying to connect multiple events in the wrong way?

edit with some extra info: My matplotlib.__version__ is 1.1.0. I have tried with GTKAgg and TkAgg backends with the same result. Using python and ipython, with or without -wthread -pylab, ipython qtconsole --pylab=inline, does not make a difference. The connection ids I get are cid0 == cid1 == 6.

edit 2: My problem still remains today with matplotlib version 1.2.x and TkAgg backend, sys.version 2.7.2+ (default, Oct 4 2011, 20:06:09) [GCC 4.6.1]

like image 631
wim Avatar asked Aug 01 '11 05:08

wim


1 Answers

I think you stumbled upon this bug: Multiple mpl_connect calls ignored

like image 115
Gerrat Avatar answered Sep 20 '22 16:09

Gerrat