[英]Wedge's pick_event handler is not called
I have the below code to display a wedge, and I would like to do something once a user clicks on the patch.我有下面的代码来显示一个楔子,一旦用户点击补丁,我想做一些事情。 Therefore I connected a handler to the
"pick_event"
and I made enabled picking the patch by passing the picker=True
keyword arg.因此,我将一个处理程序连接到
"pick_event"
,并通过传递 picker picker=True
关键字 arg 启用了选择补丁。
All is fine, except when I actually click on the patch nothing happens, ie the handler seems to not get called.一切都很好,除了当我真正点击补丁时什么都没有发生,即处理程序似乎没有被调用。
Can anyone reproduce the issue or propose a fix?任何人都可以重现该问题或提出解决方案吗?
from matplotlib.patches import Wedge
from matplotlib.collections import PatchCollection
import matplotlib.pyplot as plt
patches = [Wedge((5., 5.), 0.5, 30., 330., picker=True)]
fig, ax = plt.subplots()
ax.add_collection(PatchCollection(patches))
ax.set_xlim([0, 10.])
ax.set_ylim([0, 10.])
fig.canvas.mpl_connect('pick_event', lambda evt: print(evt))
plt.show()
When I add another ax.scatter([2.5], [2.5], picker=True)
and click on that point instead, the handler is properly called.当我添加另一个
ax.scatter([2.5], [2.5], picker=True)
并单击该点时,处理程序被正确调用。
I think you need to use the set_picker
function of the PatchCollection.我认为您需要使用
set_picker
的 set_picker function。 I didn't try but I found something of that sort in the documentation.我没有尝试,但我在文档中发现了类似的东西。 set_picker documentation
set_picker 文档
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.