python - 我正在尝试从串行终端输入的值中插入实时图表。代码总是重复第一个整数,帮助解决问题
问题描述
一些已定义的列表
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]]
解决方案
推荐阅读
- rxjs - RxJS / Redux-observables:我将如何测试 EventEmitter?
- apache-camel - 在 Camel XSLT 处理中可能导致 NullPointerException 的原因是什么?
- python - 字符串到日期字段的转换
- python - 将 Numpy 结构化数组转换为结构的 C 数组
- python-3.x - 使用 boto3 扫描 Dynamo DB 以获取字典数组
- python - Excel 电子邮件格式不同,无法打开 Python 熊猫
- java - 从以前的窗口中获取值
- react-admin - react-admin:何时首先将数据通过 List 传递给 DataGrid
- coldfusion - CF 是否不支持具有可变数量参数和任何已知解决方法的 Java 构造函数?
- airflow - 气流未按预定时间间隔运行