python - 当 matplotlib 从 csv 文件中绘制实时数据时,RAM 迅速增加
问题描述
我不是一个严肃的程序员,只是一个想法的粉丝。我创建了这个脚本。它从通过串行连接从真空传感器接收数据的日志文件中绘制最后 60 行的图形,但问题是该脚本正在迅速增加 RAM 填充。它有什么问题,我做错了什么?
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import matplotlib
matplotlib.use('TkAgg')
import csv
fig = plt.figure()
ax1 = fig.add_subplot(1,1,1)
plt.subplots_adjust(bottom=0.25)
filename = "loggedData.txt"
last_rows = 60
def update(i):
file_data = pd.read_csv(filename, skiprows = 2, delimiter=",",
header=None, parse_dates=True, usecols=[0, 1])
time_data=(file_data[0].tail(last_rows))
vacuum_data=(file_data[1].tail(last_rows))
# print(xdata)
# print(ydata)
# ax1.clear()
plt.cla()
ax1.plot(time_data,vacuum_data)
fig.autofmt_xdate(rotation=45)
ax1.set_xlabel('Measurement time')
ax1.set_ylabel('Vacuum (Torr)')
plt.yscale('log')
ax1.grid(which='major', color='#CCCCCC', linestyle='--')
ax1.grid(which='minor', color='#CCCCCC', linestyle=':')
ani = animation.FuncAnimation(fig, update, interval=1000)
plt.show()
解决方案
推荐阅读
- kubernetes - kubectl jsonpath 查询并输出多个对象值
- java - 等效于 PHP (PHPStan)中的 Java ` `/` `
- python - 将日期时间戳作为列附加到 Python 中的现有 DataFrame
- php - 在 PHP 中创建一个函数来加载和显示 CSV
- powershell - 如何使函数等待作业完成
- javascript - 如何从 axios 打印 JSON 数据?-反应-
- javascript - 在反应js中设置对象数组的状态
- apache-spark - 如何设置增量表日志保留
- javafx - 将克隆对象添加到窗格时,线程“JavaFX 应用程序线程”java.lang.IndexOutOfBoundsException 中的异常
- arrays - 重新填充该范围时,我需要保留 Excel 范围中某些行的内容