Hello my friends and welcome!
In this video, I’m going to show you a simple code to make a real time plot or figure in Python.
It is very easy and quick to customize this python code to show what you want. Let’s see.
Python code
import time
import matplotlib.pyplot as plt
import random
fig = plt.figure()
ax = fig.add_subplot()
fig.show()
x = []
n = 150 # number of data points
for i in range(n):
x.append(random.randint(0,100))
ax.plot(x, color='r')
fig.canvas.draw()
ax.set_xlim(left=max(0, i - 50), right=i + 3)
time.sleep(0.01)
plt.show()
P/s: If you find the post useful, share it to remember and to help other people as well.