I have a stream of sensor data which I want to visualize in a plot with many subplots. Plotting the data is a real bottleneck in my code. Right now I get with small resolution only 16 FPS which is far too slow.
Here is what it looks like:
import time from matplotlib import pyplot as plt import numpy as np def live_plot(): loops=100 n = 7 p = 30 fig, axes = plt.subplots(ncols=n, nrows=n) fig.canvas.draw() handles= axes = np.array(axes) for ax in axes.reshape(-1): ax.axis("off") handles.append(ax.imshow(np.random.rand(p,p), interpolation="None", cmap="RdBu")) t0 = time.time() for i in np.arange(loops): for h in handles: h.set_data(np.random.rand(p,p)) for h, ax in zip(handles, axes.reshape(-1)): ax.draw_artist(h) plt.pause(1e-12) print("avg: " + "%.1f" % (loops/(time.time()-t0)) + " FPS") live_plot()
What can I do to get more frames per second?