Faced with the fact that MatPlotlib when using self.frame.canvas.draw() I got only 12 FPS on a simple chart. I found a good article about acceleration speed MatPlotlib: https://bastibe.de/2013-05-30-speeding-up-matplotlib.html But part of the examples is working code, but the example with the fastest code (500 FPS) is not working. Attempts to read the documentation MatPlotlib have not yet led to success in understanding where the error is in the code: «AttributeError: draw_artist can only be used after an initial draw which caches the renderer». Where is the error in the code?
import matplotlib.pyplot as plt
import numpy as np
import time
fig, ax = plt.subplots()
line, = ax.plot(np.random.randn(100))
plt.show(block=False)
tstart = time.time()
num_plots = 0
while time.time()-tstart < 5:
line.set_ydata(np.random.randn(100))
ax.draw_artist(ax.patch)
ax.draw_artist(line)
fig.canvas.update()
fig.canvas.flush_events()
num_plots += 1
print(num_plots/5)