0

RemoteGraphicsView()在 PyQTGraph 的功能上遇到问题。我有一个 numpy ndarray,我希望将其绘制在 RemoteGraphicsView 上(以提高速度,因为它在单独的进程中运行)。我想绘制数据的一部分,但它因 TypeError 而失败

TypeError: must be string or single-segment read-only buffer, not numpy.ndarray

以下是一个代码片段,它演示了我在一个更大的程序中遇到的问题。可以看出,数据是一个被切片的 numpy.ndarray。

import pyqtgraph as pg
import numpy as np
import pyqtgraph.widgets.RemoteGraphicsView

app = pg.mkQApp()

datview = pg.widgets.RemoteGraphicsView.RemoteGraphicsView(debug=False)
datview.pg.setConfigOptions(antialias=True) 
allplots = datview.pg.GraphicsLayout()
datview.setCentralItem(allplots)

w1 = allplots.addPlot(row=0,col=0)

layoutWG = pg.LayoutWidget()
layoutWG.addWidget(datview)
layoutWG.show()

data = np.random.randn(10000,100)
curve1 = w1.plot(pen='r')

now = pg.ptime.time()
for n in range(100):
    curve1.setData(data[:,n])
    app.processEvents()

app.exec_()

任何帮助将非常感激。

4

1 回答 1

1

Looks like the interprocess communication system requires a contiguous array. This should work:

    curve1.setData(np.ascontiguousarray(data[:,n]))

Alternatively, you can define the data such that the slices you want are already contiguous:

data = np.random.randn(100,10000)
...
for n in range(100):
    curve1.setData(data[n])

I also recommend a couple of changes to speed things up:

# Prevent lookups to curve1.setData from immediately requesting and returning
# the method proxy every time it is called
curve1._setProxyOptions(deferGetattr=True)

for n in range(100):
    # Use _callSync='off' to prevent the main process waiting for a return 
    # value
    curve1.setData(np.ascontiguousarray(data[:,n]), _callSync='off')
于 2014-04-23T13:00:11.667 回答