# Live plot with many subplots

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?

• You would probably get better answers if you included some sample data in your question. – 200_success Oct 28 '18 at 12:23
• @200_success My sensors stream at 120 FPS. Random numbers from numpy are fine to simulate sensor data and real data are probably not essential to make the code run faster. Please tell me if I am wrong. – random9 Oct 28 '18 at 12:30
• Isn't 120 FPS way too fast to actually notice if anything meaningful changed in some frame? In other words, wouldn't it make it better to collate data for, say, one second and display that? – Graipher Oct 29 '18 at 11:26
• @Graipher In low resolution my sensors steam at 120 FPS. At higher resolution the frame rate drops quickly and my code is even slower. – random9 Oct 29 '18 at 11:35