单击两点时是否可以绘制特定值?

时间:2019-09-13 10:17:10

标签: python matplotlib onclick

我正在开发一个项目,当您单击两个点时,它将绘制我设置的x和y值。我是matplotlib的新手,所以我不知道是否有可能。

    import matplotlib.pyplot as plt

    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.set_xlim([0, 10])
    ax.set_ylim([0, 10])

    def onclick(event):
        print('button=%d, x=%d, y=%d, xdata=%f, ydata=%f' %
        (event.button, event.x, event.y, event.xdata, event.ydata))
        if event.x == 215 and event.x == 420:
           plt.plot([2,5],[3,3])

    plt.plot(event.xdata, event.ydata, '-ro')
    fig.canvas.draw()

    cid = fig.canvas.mpl_connect('button_press_event', onclick)
    plt.show()

我希望每次单击两点时,都会出现我设置为绘制的值。

0 个答案:

没有答案