简体   繁体   English

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

[英]Real time plotting using Matplotlib. X axis getting over-written

更新代码 I'm plotting real-time data using parsed data from a file that is being repeatedly opened.我正在使用重复打开的文件中的解析数据绘制实时数据。 The plotting works great until the X axis (time) runs out a room.绘图效果很好,直到 X 轴(时间)用完一个房间。 I'm trying to figure out a way to advance to the next element and shift the time values to the left.我试图找出一种方法来前进到下一个元素并将时间值向左移动。 Code and screenshot included here.此处包含代码和屏幕截图。

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()

在此处输入图片说明

You could just rotate the labels,你可以旋转标签,

for label in ax.get_xticklabels():
    label.set_rotation(90)

or或者

ax.tick_params('x', labelrotation=90)

before calling plt.plot() .调用plt.plot()之前

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM