一些已定义的列表
m = []
n = []
x = []
y = []
读取串行数据并将其存储在数组中的函数
def animation_frame(i):
data = (ser.read(2))
temp = int(data)
m.append(temp)
n.append(i)
转换为 int 列表
list(map(int, m))
list(map(int, n))
更改 numpy 数组中的列表
x = np.array([n])
y = np.array([m])
删除重复项
res = [i for p, i in enumerate(x) if i not in x[:p]]
return line,
调用动画函数并绘制实时数据的永远循环
while True:
animation = FuncAnimation(fig, func=animation_frame,frames=np.arange(0,
1000,1),interval=200)
plt.show()
i += 1
这就是问题所在,在我尝试打印'n []'数组之后,它正在复制第一个列表元素..
[[0]]
[[0 0]]
[[0 0 1]]
[[0 0 1 2]]
[[0 0 1 2 3]]
[[0 0 1 2 3 4]]
[[0 0 1 2 3 4 5]]
[[0 0 1 2 3 4 5 6]]
[[0 0 1 2 3 4 5 6 7]]
[[0 0 1 2 3 4 5 6 7 8]]