【问题标题】:Storing two mouse events on Python [duplicate]在Python上存储两个鼠标事件[重复]
【发布时间】:2022-01-12 18:30:21
【问题描述】:

我目前正在使用 matplotlib,我需要在图表上存储两次左键单击的坐标。 (我正在计算两个点击点之间的积分)不知何故,经过数小时的尝试,我还没有设法保存两次点击。这里有人知道怎么做吗?

【问题讨论】:

标签: python matplotlib tkinter mouseevent


【解决方案1】:

使用ginput() 函数。这是一个例子:

import numpy as np
import matplotlib.pyplot as plt

# generate some data to plot
x = np.linspace(0, 10)
y = np.sin(x)

plt.plot(x, y)

print('please click twice on the plot')

clicks = []
for i in range(2):
    clicks.append(plt.ginput())

print('your clicks were at locations:')
print(clicks)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多