1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| # -*- coding: utf-8 -*-
# https://stackoverflow.com/questions/11874767/how-do-i-plot-in-real-time-in-a-while-loop-using-matplotlib
from datetime import datetime
from matplotlib import pyplot
from matplotlib.animation import FuncAnimation
from random import randrange
refreshRate=1000
x_data, y_data = [], []
figure = pyplot.figure()
line, = pyplot.plot_date(x_data, y_data, '-')
pyplot.title('Power Max (dB)')
pyplot.grid(True)
counter=1
max=0
def update(frame):
global counter
global max
with open("maxPower.txt", "r") as fichier:
for i in range(counter):
power = fichier.readline()
if (power!=""):
if (power>max):
max=power
x_data.append(datetime.now())
# x_data.append(counter)
y_data.append(float(power))
counter=counter+1
line.set_data(x_data, y_data)
figure.gca().relim()
figure.gca().autoscale_view()
return line,
animation = FuncAnimation(figure, update, interval=refreshRate)
pyplot.show() |
Partager