wiwinut
wiwinut

Reputation: 75

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

update codeI'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. 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()

enter image description here

Upvotes: 1

Views: 374

Answers (1)

William Miller
William Miller

Reputation: 10330

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

Upvotes: 1

Related Questions