【发布时间】:2021-07-08 10:44:39
【问题描述】:
我有一些与 spyder 一起使用的代码行(使用 matplotlib),它们允许我保存双击的坐标。由于某种原因,我不明白相同的代码在 Jupyter Notebook 中不起作用。
coords = []
class onclick:
""" Saves the coordinates of the left-double-clicked points and finishes with right-double-click """
def __init__(self):
self.cid = fig.canvas.mpl_connect('button_press_event', self)
def __call__(self, event):
global ix, iy
global coords
if event.dblclick:
if event.button==1:
ix, iy = event.xdata, event.ydata
print ('Coordinate clicked: %.3f, %.3f'%(ix, iy))
coords.append((ix, iy))
if event.button==3:
fig.canvas.mpl_disconnect(self.cid)
print("Clicked points saved in 'coords'")
return
cid = onclick()
有什么方法可以在 Jupyter Notebook 中完成这项工作?
(不知道这是否相关,但在 Jupyter Notebook 中我使用 %matplotlib notebook 可以放大)
【问题讨论】:
标签: python-3.x matplotlib graph jupyter-notebook