每次向我的csv文件中添加新值时,我都会运行这个脚本进行更新(这是一个从机器中获取值的手动日志):
from itertools import count
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
plt.style.use('fivethirtyeight')
x_vals = []
y_vals = []
counter=0
index = count()
def animate(i):
data = pd.read_csv('C:/Users/Owner/Downloads/Manual-Log-27Nov2020-150846.csv')
data=data.dropna()
data['Date And Time']=data['Date']+' '+data['Time']
Date = data['Date And Time']
Temp = data['Temperature']
Pressure = data['Pressure']
pH = data['pH']
plt.cla()
plt.plot(Date, Temp, label='Temperature')
plt.plot(Date, Pressure, label='Pressure')
plt.plot(Date, pH, label='pH')
plt.legend(loc='upper left')
plt.xlabel('Date and Time')
plt.ylabel('Y Values')
plt.xticks(rotation=90)
plt.tight_layout()
ani = FuncAnimation(plt.gcf(), animate, interval=30000)
plt.tight_layout()
plt.show()
由于它是一个如此大的文件(20k行左右),因此生成的图形非常庞大,您无法真正正确地读取数据。有没有办法我只能让它显示最近的20个读数?
1条答案
按热度按时间ukdjmx9f1#
您可以将其切片或获取前n条记录。可以在代码行之后应用以下内容:data=data.dropna()