Skip to content

Instantly share code, notes, and snippets.

@ugo-nama-kun
Last active June 30, 2023 06:00
Show Gist options
  • Save ugo-nama-kun/9e16baa672d5e3b466d9100be5d8a879 to your computer and use it in GitHub Desktop.
Save ugo-nama-kun/9e16baa672d5e3b466d9100be5d8a879 to your computer and use it in GitHub Desktop.
Online Plotting with Matplotlib
import matplotlib.pyplot as plt
import numpy as np
from collections import deque
plt.figure()
ax = plt.subplot(1,1,1)
plt.ylim([-1.1, 1.1])
plt.xlim([0, 50])
# data
data = deque([0]*50, maxlen=50)
lines = plt.plot(data)
for i in range(1000):
new = 2 * np.random.rand() - 1
data.append(new)
# Plotting
lines[0].set_ydata(data)
plt.pause(0.1) # drawing
@ugo-nama-kun
Copy link
Author

Requirements: matplotlib, numpy

@ugo-nama-kun
Copy link
Author

Dec-04-2020 17-43-43

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment