【发布时间】:2020-01-11 19:53:17
【问题描述】:
我正在使用重复打开的文件中的解析数据绘制实时数据。绘图效果很好,直到 X 轴(时间)用完一个房间。我试图找出一种方法来前进到下一个元素并将时间值向左移动。此处包含代码和屏幕截图。
import matplotlib.pyplot as plt
import csv
import datetime
from matplotlib.animation import FuncAnimation
x = []
y = []
rssi_val = []
def animate(i):
with open('stats.txt', 'r') as searchfile:
# time = (searchfile.read(5))
time = (searchfile.read(8))
for line in searchfile:
if 'agrCtlRSSI:' in line:
rssi_val = line[16:20]
y.append(rssi_val)
x.append(time[-1])
plt.cla()
plt.plot(x,y)
next(x)
plt.xlabel('Time')
plt.ylabel('RSSI')
plt.title('Real time signal strength seen by client X')
plt.tight_layout()
ani = FuncAnimation(plt.gcf(), animate, interval=5000)
plt.show()
【问题讨论】:
标签: python matplotlib real-time