确定点是否位于Matplotlib子P中

2024-04-24 23:11:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个Matplotlib图,有几个子图。我希望在单击位置1中的子批时执行一个函数。从事件处理程序生成的事件对象中,如何确定是否单击了子批?你知道吗


Tags: 对象函数处理程序matplotlib事件
1条回答
网友
1楼 · 发布于 2024-04-24 23:11:16

作为属性inaxes进入回调的event对象,它是单击的轴。你知道吗

import matplotlib.pyplot as plt
fig, ax_list = plt.subplots(2, 2)
ax_list = ax_list.ravel()
ax_list[0].set_gid('A')
ax_list[1].set_gid('B')
ax_list[2].set_gid('C')

def clicker(event):
    print(event.inaxes.get_gid())

fig.canvas.mpl_connect('button_press_event', clicker)
plt.show()

相关问题 更多 >