Created
August 13, 2019 16:49
-
-
Save bcattle/219a3e9482e45dc5bd9babb43e480dc2 to your computer and use it in GitHub Desktop.
Live update plotting of a random timeseries using matplotlib
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ours, no blit, plot a timeseries | |
from datetime import datetime | |
from matplotlib import pyplot | |
from matplotlib.animation import FuncAnimation | |
from random import randrange | |
import numpy as np | |
n_pts = 256 | |
x_data = np.linspace(0, n_pts-1, n_pts) | |
y_data = np.zeros(n_pts) | |
figure = pyplot.figure() | |
line, = pyplot.plot(x_data, y_data, '-') | |
def update(frame): | |
# TODO: collect new data here | |
y_data = np.random.rand(256) | |
line.set_data(x_data, y_data) | |
figure.gca().relim() | |
figure.gca().autoscale_view() | |
return line, | |
animation = FuncAnimation(figure, update, interval=200) | |
pyplot.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment