【问题标题】:Jupyter notebook: saving graph coordinatesJupyter notebook:保存图形坐标
【发布时间】: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


    【解决方案1】:

    由于缺乏响应,我做了一个解决方法,我使用鼠标右键单击而不是双击来保存坐标。这在 Jupyter Notebook 中运行良好。代码如下:

    coords = []
    def onclick(event):
        global coords
        if event.button == 3:
            coords.append(event.xdata)
    
    cid = fig.canvas.mpl_connect('button_press_event', onclick)
    

    【讨论】:

      猜你喜欢
      • 2021-02-06
      • 2020-05-10
      • 1970-01-01
      • 1970-01-01
      • 2018-10-23
      • 2017-05-28
      • 2018-04-25
      • 2020-12-10
      • 1970-01-01
      相关资源
      最近更新 更多