【发布时间】:2021-09-13 12:16:46
【问题描述】:
我正在使用 plt.connect 将光标经过的点保存到坐标列表中,并且我想绘制这些点,但是在断开绘图后我无法做任何事情并且绘图自行关闭. 我找不到任何例子,在连接情节之后,你可以对情节做任何事情。 这是我要修复的代码:
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.backend_bases import MouseButton
t = np.arange(0.0, 1.0, 0.01)
s = np.sin(2 * np.pi * t)
fig, ax = plt.subplots()
ax.plot(t, s) #just plot something
x=[]
y=[]
def on_move(event):
global x,y
if event.inaxes:
x.append(event.xdata)
y.append(event.ydata)
print('data coords %f %f' % (event.xdata, event.ydata))
plt.waitforbuttonpress()
binding_id = plt.connect('motion_notify_event', on_move)
plt.pause(5) #5 seconds to collect data
plt.disconnect(binding_id) #here it closes by itself
ax.plot(x,y)
【问题讨论】:
标签: python numpy matplotlib