Pyqtgraph绘图很慢

时间:2018-02-08 16:09:49

标签: qt pyqt pyqtgraph

每次添加新的rect时,似乎窗口会重新绘制所有内容,尽管setUpdatesEnabled设置为False, win plt 即可。如何禁用更新?

def f(n):
    import pyqtgraph as pg
    pg.setConfigOption('background', '#a0f0ff')
    win = pg.GraphicsWindow()
    win_size = 1000
    win.setGeometry(500, 30, win_size, win_size)
    plt = win.addPlot()
    win.setUpdatesEnabled = False
    plt.setUpdatesEnabled = False
    y = range(n)
    x = range(n)
    plt.showGrid(x=True, y=True)
    empty_pen = pg.mkPen((0, 0, 0, 0))
    brush = pg.mkBrush((255, 255, 255))
    for i1 in range(n):
        for i0 in range(n):
            print("i1, i0 =", i1, i0)
            rect = pg.QtGui.QGraphicsRectItem(i0, i1, 0.5, 0.5)
            rect.setPen(empty_pen)
            rect.setBrush(brush)
            plt.addItem(rect)
    pg.QtGui.QApplication.exec_()

f(40)

1 个答案:

答案 0 :(得分:1)

添加

plt.disableAutoRange()
在绘制之前

plt.autoRange()

之后。见Plotting large arrays in pyqtgraph