python - 使用 Matplotlib 进行实时绘图。 X 轴被覆盖

标签 python matplotlib real-time

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

最佳答案

您可以旋转标签,

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

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

调用plt.plot()之前。

关于python - 使用 Matplotlib 进行实时绘图。 X 轴被覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59698123/

相关文章:

python - 使用色调颜色为极坐标条形图着色,在 0 处不间断

flutter - 如何做一个有 flutter 的相机滤镜?

python - 在Python中优化四个参数scipy.optimize.fmin_l_bfgs_b,出现错误

python - django:将无盐 md5(无盐)哈希转换为 pbkdf2

Python:如何替换并知道是否匹配

python - Pandas 使用滚动总和和递减窗口创建新列

python - 图像未转换为灰度

python - 拆分数据并使用 Python 用实线和虚线绘制它们

c - C/C++ 中的实时间隔

c - 如何编写rt-linux的内核模式?