matplotlib与事件处理程序的多个连接?

wim*_*wim 10 python events matplotlib event-handling

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()
Run Code Online (Sandbox Code Playgroud)

使用上面的代码,为什么我不能同时触发鼠标按键事件和按键事件?似乎按上面的顺序只有按键事件工作,而如果我交换第10行和第11行(命令cid0和cid1赋值),那么只有鼠标事件才有效.即我连接的任何一个第一个占用事件处理程序.这是matplotlib的内置限制,还是我试图以错误的方式连接多个事件?

编辑一些额外的信息:我matplotlib.__version__1.1.0.我尝试过GTKAggTkAgg后端同样的结果.使用Python和IPython中,有或无-wthread -pylab,ipython qtconsole --pylab=inline不有所作为.我得到的连接ID是cid0 == cid1 == 6.

编辑2:我的问题仍然存在于matplotlib版本1.2.xTkAgg后端,sys.version 2.7.2+ (default, Oct 4 2011, 20:06:09) [GCC 4.6.1]

Ger*_*rat 4

我认为您偶然发现了这个错误:忽略多个 mpl_connect 调用