调整大小后pyqtgraph实时图冻结

pyqtgraph real time plot freezes after resizing

我正在 pyqtgraph 中绘制通过 UDP 接收的实时数据。每次更新 2048 点一切都很好,但是当我尝试调整大小或放大时,如果有 4096 或 8k 点,绘图就会冻结。如果我切换 logY 比例,更新将恢复。我已验证 UDP 流中没有间隙。还尝试使用

# p.setDownsampling(auto=True)
# p.setClipToView(True)

选项,但没有帮助

我听说 pyqtgraph 可以处理比这多得多的数据,所以我有点疑惑。问题可以在这里看到:https://www.youtube.com/watch?v=iL-WHEbSx-w

这是代码,我直接从例子中拿来的,只做了一些小改动

from pyqtgraph.Qt import QtGui, QtCore
import numpy as np
import pyqtgraph as pg
from pyqtgraph.ptime import time

from struct import pack, unpack

from socket import *

app = QtGui.QApplication([])

data = []

p = pg.plot(fillLevel=20)
p.setWindowTitle('pyqtgraph example: PlotSpeedTest')
p.setRange(QtCore.QRectF(0, 0, 30720000, 10 )) 
p.setLabel('bottom', 'Frequency', units='Hz')
p.showGrid(True, True)
fScale = np.linspace(0, 30720000, 8192)

# p.setDownsampling(auto=True)
# p.setClipToView(True)

curve = p.plot()

# Receive UDP packets transmitted by a broadcasting service

sock = socket(AF_INET, SOCK_DGRAM)
try:
        sock.bind(('', 1234))
except:
        print "Error connecting to the UDP stream."
        quit


ptr = 0
lastTime = time()
fps = None
def update():
    global sock, fScale
    global curve, data, ptr, p, lastTime, fps
    stream = sock.recv(16384)
    if (len(stream) == 16384):
        data_float16 = np.fromstring(stream, dtype=np.float16)
        data = data_float16.astype(np.float32)
        print "got data", lastTime, "\n"
    # print data
    curve.setData(fScale,data,_callSync='off')
    # curve.setData(data,_callSync='off')
    now = time()
    dt = now - lastTime
    lastTime = now
    if fps is None:
        fps = 1.0/dt
    else:
        s = np.clip(dt*3., 0, 1)
        fps = fps * (1-s) + (1.0/dt) * s
    p.setTitle('%0.2f fps' % fps)
    app.processEvents()  ## force complete redraw for every plot
timer = QtCore.QTimer()
timer.timeout.connect(update)
timer.start(0)


## Start Qt event loop unless running in interactive mode.
if __name__ == '__main__':
    import sys
    if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
        QtGui.QApplication.instance().exec_()

如果数据中有任何 Inf,那么它会混淆确定是否重绘绘图的边界矩形计算。先尝试清理数据:

data[np.isinf(data)] = np.nan