I have been trying to figure out how to make a real time updating graph using Matplotlib, without using FuncAnimation()
because it was too slow for my final purpose. I read through This Article, which explains how to speed up the plotting in Matplotlib. I then tried to implement his method with a real time graph method, but unfortuanately I still have only basic Python/Matplotlib skills to do such a thing.
I was able to get as far as creating an x and y limit and creating a blank line which I would like to update in a while loop with random numbers for now. I am able to create random numbers every loop but I am unable to update the numbers to the graph. I do not want the x values to change but rather the y values to change while being updated. Something that looks like a heart monitor would for example. Here is my following code up to where I am stuck:
import matplotlib.pyplot as plt
import random
x_len = 100
y_range = [-1,10]
xs = list(range(0,100))
ys = [0] * x_len
fig, ax = plt.subplots()
line, = ax.plot(xs,ys)
ax.set_ylim(y_range)
plt.show(block=False)
fig.canvas.draw()
while True:
y = random.randint(-10,10)
line.set_ydata(ys)
ax.draw_artist(ax.patch)
ax.draw_artist(line)
fig.canvas.flush_events()
print("one loop")
print(y)