Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 确定点是否位于Matplotlib子地块中_Python_Matplotlib_Subplot - Fatal编程技术网

Python 确定点是否位于Matplotlib子地块中

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

我有一个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].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.y
x
y
在像素空间
xdata
ydata
在数据空间中。那么,您如何从不同的方法访问(并设置数据)子地块?