5

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?

2
  • try to do it by multithread your cpu Commented Mar 11, 2020 at 8:01
  • Can you give a simple example? Would you draw the objects using Python's multiprocessing toolbox? Commented Mar 11, 2020 at 8:59

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for the answer. I tried to lower the resolution using rcParams["figure.dpi"] = 50. Now, however, many objects are just much smaller. How do I correctly lower the amount of pixels that need to be drawn?
That's the purpose of lowering the figure size or dpi. I don't think this will lead anywhere without a concrete minimal reproducible example of the issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.