Pyqtgraph 绘图很慢

Posted

技术标签:

【中文标题】Pyqtgraph 绘图很慢【英文标题】:Pyqtgraph plotting is slow 【发布时间】:2018-07-19 06:48:28 【问题描述】:

对于 winplt,尽管 setUpdatesEnabled 设置为 False,但似乎每次添加新矩形时窗口都会重绘所有内容。如何禁用更新?

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】:

添加

plt.disableAutoRange()

在绘制之前和

plt.autoRange()

之后。见Plotting large arrays in pyqtgraph

【讨论】:

以上是关于Pyqtgraph 绘图很慢的主要内容,如果未能解决你的问题,请参考以下文章

重新启动实时绘图时,pyqtgraph实时绘图中断

在pyqtgraph中实现实时绘图的最简单方法是啥

pyqtgraph绘图安装pyqtgraph

pyqtgraph绘图线条,填充和颜色

如何在pyqtgraph中缩放绘图

pyqtgraph绘图如何使用pyqtgraph