【发布时间】:2020-01-10 20:32:39
【问题描述】:
我会先说我还在学习 Python,所以请耐心等待。我的代码如下:
- 网络上的客户端每约 5 秒向 SCP 服务器发送一个文本文件 (stats.txt)。 Python 代码位于服务器上。
以下代码开始:
import matplotlib.pyplot as plt
import csv
import datetime
x = []
y = []
rssi_val = []
def animate(i):
with open('stats.txt', 'r') as searchfile:
time = (searchfile.read(5))
for line in searchfile:
if 'agrCtlRSSI:' in line:
rssi_val = line[16:20]
y = [rssi_val]
x = [time for i in range(len(y))]
plt.xlabel('Time')
plt.ylabel('RSSI')
plt.title('Real time signal strength seen by client X')
#plt.legend()
plt.plot(x,y)
ani = FuncAnimation(plt.gcf(), animate, interval=5000)
plt.tight_layout()
#plt.gcf().autofmt_xdate()
plt.show()
- SCP 服务器每 5 秒打开一次文件并绘制从文件中解析的值。时间绘制在 X 轴上,RSSI 值绘制在 Y 轴上。
我了解目前使用的代码和方法效率不高,将来会进行修改。现在,我只希望每 5 秒左右显示一次绘图值,并用绘图(线)对图表进行动画处理。
运行它不会产生任何结果。
【问题讨论】:
-
每个新文件是否包含单个 RSSI 值?
标签: python matplotlib jquery-animate