给定一个有多个绘图的图形,有没有一种方法可以确定哪些是用鼠标键单击的?在
例如
fig = plt.figure()
ax = fig.add_subplot(121)
ax.imshow(imsp0)
ax = fig.add_subplot(122)
ax.imshow(imsp1)
fig.canvas.mpl_connect("button_press_event",onclick_select)
def onclick_select(event):
... do something depending on the clicked subplot
如果您保留了两个轴的句柄,您可以只查询单击发生的轴;例如
if event.inaxes == ax:
至少可以采用以下步骤:
onclick事件具有
x
和y
属性,它们携带图形角落的像素坐标可以使用
将这些坐标转换为图形坐标fig.transFigure.inverted().transform((x,y))
您可以通过
bb=ax.get_position()
迭代图像的所有子图(轴)
您可以通过}是转换为图像位置的按钮单击坐标
bb.contains(fx,fy)
来测试单击是否在该边界框的区域内,其中fx
和{有关onclick事件的详细信息:http://matplotlib.org/users/event_handling.html 有关坐标变换的详细信息:http://matplotlib.org/users/transforms_tutorial.html
相关问题 更多 >
编程相关推荐