我正在尝试将鼠标左键单击坐标保存到matplotlib图形的列表中。以下是我迄今为止所写的内容:
def onclick(event):
coord = [event.xdata,event.ydata]
print(coord)
return coord
def locate():
fig = plt.gcf()
cid = fig.canvas.mpl_connect('button_press_event',onclick)
fig.canvas.mpl_disconnect(cid)
正如您可能已经从我的代码中了解到的,我是Python新手。使用上述代码,我无法返回coord
。我试图使coord
成为global
变量,但没有得到结果。
我想在一次鼠标点击后断开与图形的连接,并将坐标保存为列表。
基本上,我希望语句coordinates = locate()
将列表保存到变量coordinates
。
我在Juypter笔记本上工作
类似的问题:get Coordinates of matplotlib plot figure python with mouse click
目前没有回答
相关问题 更多 >
编程相关推荐