문제

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.

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top