【问题标题】:Event OnClick Matplotlib display points and save事件 OnClick Matplotlib 显示点并保存
【发布时间】:2021-07-22 17:17:18
【问题描述】:

matplotlib 文档中那个帖子的问题解决:https://matplotlib.org/stable/users/event_handling.html

【问题讨论】:

    标签: python matplotlib onclick qt-designer


    【解决方案1】:

    第一个问题,你可以看看这个

    Matplotlib Plot Points Over Time Where Old Points Fade

    第二个,试试这样的

    #list to store the points
    points = []
    
    #click event
    def onclick(event):
        global points
        print('button=%d, x=%d, y=%d, xdata=%f, ydata=%f' %
              (event.button, event.x, event.y, event.xdata, event.ydata))
        #store the points in a list
        points.append([event.x, event.y, event.xdata, event.ydata])
        plt.plot(event.xdata, event.ydata, ',')
    

    每次单击时,点集都会添加到点列表中。反之亦然,如果您想访问例如坐标,通过第三次点击存储,只需输入

    print(f"x={points[2][0]}, y={points[2][1]}, xData={points[2][2]}, yData={points[2][3]}")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-10
      • 1970-01-01
      • 2021-06-22
      • 2015-05-27
      • 2015-05-21
      • 1970-01-01
      • 2021-09-13
      相关资源
      最近更新 更多