1

I am trying to develop a PyQT5 application with Matplotlib, similar in structure to the accepted answer in How to use a Qthread to update a Matplotlib figure with PyQt?

The problem that I am facing is performance. A requirement for the application is multiple(up to about 20) matplotlib graphs that are updated randomly, but often within milliseconds. Each chart has 200-2000+ objects (lines and rectangles mostly). I've optimized the plotting process as much as I could, however depending on the number of objects on the graph I am facing drawing times of approx 40-300ms per graph.

I was hoping to at least use qthread to offload the drawing process (mainly .draw(), and/or anything that uses figure()) to another thread to keep the gui responsive, but it seems like all drawing has to be done in the main thread. Therefore, any other threading solution like multiprocess or similar would not work, too.

So basically, worst case szenario, if all 20 graphs update at the same time the gui would be unresponsive for 20*300ms. As I understand it, using QMdiSubWindow would not result in that subwindow to use an extra thread, so until all graphs are updated, the complete gui would freeze.

I see the following solutions to this problem:

  • Switch to another plotting library, maybe one where part of the drawing process can be threaded (or performance is much, much better). Suggestions?
  • Switch to another programming language (I.e. Java and Qt Jambi. But would the rule that drawing has to be done in the main thread of a Qt application not apply there too?)
  • Spawn multiple, independent main gui processes, one for each graph(so one window per graph), and let them communicate with a server process that distributes the data that the chart clients should plot.
  • use matplotlib in a subthread / multiprocess thread, but not as a widget. Instead, create an image, give that image back to the main process for display. That would probably add more display latency (but greatly improve gui responsiveness), and interacting with the now image would be more difficult and probably result in reduced interaction options. Probably a very unclean solution.

Do I understand the situation right? Are there other, better ways?

Community
  • 1
  • 1
harbun
  • 515
  • 6
  • 23
  • It would be better if you were able to post program code that demonstrates the problem. When I tested [pyqtgraph](http://www.pyqtgraph.org/) a little bit I got the feeling that it could be faster than matplotlib but I have not done any extensive comparison. – J.J. Hakala Apr 07 '17 at 12:48
  • 1
    Matplotlib is not meant for high performance and fast plotting; it's designed for producing appealing graphics. `pyqtgraph` is indeed much faster, see e.g. *[here](http://stackoverflow.com/a/40139416/4124317)* for a comparison. – ImportanceOfBeingErnest Apr 07 '17 at 14:11
  • I did this... https://stackoverflow.com/questions/48603249/python-ipc-with-matplotlib/48838306#48838306 – csandy83 Mar 16 '18 at 15:00

0 Answers0