Question

I want to add about 200 plots into the graphicsLayoutWidget, when I click one button.But now the gui freezes for about 10 seconds. How can I avoid this.

Was it helpful?

Solution

This is a flaw in pyqtgraph.

It looks like the majority of initialization time is taken up creating context menus. PlotItem.__init__ and ViewBox.__init__ both have "enableMenu" arguments, but setting these to False simply stops the menu from appearing and does not stop them being created.

So the easiest way to fix this is to simply avoid creating the menus at all, and a better way would be to defer the menu creation until the user right-clicks on the plot. You can try the former solution by checking out this code: https://github.com/lcampagn/pyqtgraph/tree/deferred_menu

Under that code, the following example runs much faster:

import pyqtgraph as pg
w = pg.GraphicsWindow()
for i in range(20):
    for j in range(20):
        w.addPlot(enableMenu=False)
    w.nextRow()

The latter solution would require more extensive changes. Further performance improvements could be made by avoiding displaying AxisItems

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top