使用Matplotlib实时绘图。 X轴被覆盖

问题描述 投票:1回答:1

update code我正在使用来自反复打开文件的解析数据来绘制实时数据。直到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()

enter image description here

python matplotlib real-time
1个回答
0
投票

您可以旋转标签,

for label in ax.get_xticklabels():
    label.set_rotation(90)
© www.soinside.com 2019 - 2024. All rights reserved.