matplotlib多个连接到事件处理程序? [英] matplotlib multiple connections to an event handler?

查看:172
本文介绍了matplotlib多个连接到事件处理程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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()

使用上面的代码,为什么我不能同时鼠标按下事件和按键事件触发?似乎按照上面的顺序只有按键事件的工作,而如果我交换线10和11(订单cid0和cid1分配),那么只有鼠标事件工作。即无论我先连接哪一个,都会生成事件处理程序。这是否是matplotlib的内在限制,或者我是否以错误的方式连接多个事件?

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?

使用一些额外的信息编辑:我的 matplotlib .__版本__ 1.1.0 。我尝试与 GTKAgg TkAgg 后端具有相同的结果。使用python和ipython,有或没有 -wthread -pylab ipython qtconsole --pylab = inline ,不会一个区别。我得到的连接ID是 cid0 == cid1 == 6

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.

编辑2 :我的问题仍然是今天matplotlib版本 1.2.x TkAgg 后端, sys.version 2.7.2+(默认,2011年10月4日,20:06:09)[ GCC 4.6.1]

推荐答案

我想你偶然发现这个错误:忽略多个mpl_connect调用

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

这篇关于matplotlib多个连接到事件处理程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆