Speeding up Matplotlib

Viewed 544

Currently I am working on a real-time plot but the visualization is really slow. I would like to know what things in general you can do to speed up things in Matplotlib:

  • How does the backend affect the performance? Are there backends that are better for real time plotting than others?
  • Can I lower the resolution to increase FPS?
  • Why does the FPS of my plot increase if I reduce the window size? Why does FPS drop dramatically if I switch to full screen mode?

I also tried to turn off everything I don't need:

ax.set_xticklabels(())
ax.set_yticklabels(())
ax.set_xticks([])
ax.set_yticks([])
ax.axis('off')
ax.get_xaxis().set_visible(False)
ax.get_yaxis().set_visible(False)

However, the effect is negligible. Are there more things I can turn off?

I would also like to know if it is possible to turn off the buttons (home button, etc.., see below) of the window that opens when creating a graph. May turning off these buttons increase the speed?

enter image description here

I also found that doing the following

fig.canvas.draw_idle()
fig.canvas.start_event_loop(1e-9)

is much slower for updating the plot than

fig.canvas.draw_idle()
self.fig.canvas.update()
self.fig.canvas.flush_events()

Are there even better ways to update the objects in a plot?

1 Answers

How does the backend affect the performance? Are there backends that are better for real time plotting than others?

The backend plays two roles: First, it renders everything, so the faster it renders, the faster the output. Second, the GUI toolkit used may play a role, because it may limit how fast an updated canvas is displayed. It seems "Qt5Agg" is faster than "TkAgg" for example.

Can I lower the resolution to increase FPS?

You can make the figure smaller, or use a smaller dpi. Both will decrease the amount of pixels that need to be drawn and hence speed up drawing.

Why does the FPS of my plot increase if I reduce the window size? Why does FPS drop dramatically if I switch to full screen mode?

As above, more pixels that need to be drawn on screen mean slower rendering.

Are there more things I can turn off?

We don't know what you have in your code, so we can't know what to turn off.

May turning off these buttons increase the speed?

No.


Finally, fig.canvas.draw_idle() in itself should be sufficient to update the plot, because usually you would have the event loop running already. Restarting an event loop is not helpful.

Related