Python 确定点是否位于Matplotlib子地块中
我有一个Matplotlib图,有几个子图。我希望在单击位置1中的子批次时执行一个函数。如何从事件处理程序生成的事件对象确定是否单击了子批次?作为属性Python 确定点是否位于Matplotlib子地块中,python,matplotlib,subplot,Python,Matplotlib,Subplot,我有一个Matplotlib图,有几个子图。我希望在单击位置1中的子批次时执行一个函数。如何从事件处理程序生成的事件对象确定是否单击了子批次?作为属性inaxes进入回调的事件对象,即单击的轴 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].se
inaxes
进入回调的事件对象,即单击的轴
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()
你能给我们看一些示例代码吗?谢谢!然后,我将如何计算该子地块内单击的坐标?例如,如果子地块1包含一个图像,我单击该图像的坐标0,0,当我访问event.x时,我得不到0,0。event.yx
和y
在像素空间xdata
和ydata
在数据空间中。那么,您如何从不同的方法访问(并设置数据)子地块?