Python 如何在pyqtgraph remoteview上绘制切片numpy数据数组

Python 如何在pyqtgraph remoteview上绘制切片numpy数据数组,python,arrays,qt,numpy,pyqtgraph,Python,Arrays,Qt,Numpy,Pyqtgraph,我在PyQTGraph中的RemoteGraphicsView()功能性方面遇到问题。我有一个numpy ndarray,我希望在RemoteGraphicsView上绘制它(因为它在一个单独的进程中运行时速度更快)。我想绘制一段数据,但由于类型错误而失败 TypeError: must be string or single-segment read-only buffer, not numpy.ndarray 下面是一个代码片段,它演示了我在一个更大的程序中遇到的问题。可以看到,数据是一个

我在PyQTGraph中的
RemoteGraphicsView()
功能性方面遇到问题。我有一个numpy ndarray,我希望在RemoteGraphicsView上绘制它(因为它在一个单独的进程中运行时速度更快)。我想绘制一段数据,但由于类型错误而失败

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_()

任何帮助都将不胜感激。

看起来进程间通信系统需要一个连续阵列。这应该起作用:

    curve1.setData(np.ascontiguousarray(data[:,n]))
或者,您可以定义数据,以便所需的切片已经是连续的:

data = np.random.randn(100,10000)
...
for n in range(100):
    curve1.setData(data[n])
我还建议进行一些更改以加快速度:

# 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')

谢谢你的评论。我在主程序中设置了这两个选项(我按照您的示例比较了本地和远程打印)。我还发现
data[:,n].copy()
也可以工作。我可能会恢复到本地绘图,因为我需要访问其他一些重要功能,如
LinearRegionItem
,它也不喜欢在远程绘图上运行