简体   繁体   English

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

[英]How do I plot a sliced numpy data array on a pyqtgraph remoteview

I am having trouble with the RemoteGraphicsView() functionallity in PyQTGraph. 我在PyQTGraph中的RemoteGraphicsView()功能上遇到麻烦。 I have a numpy ndarray which I wish to plot on a RemoteGraphicsView (for speed as it runs in a seperate process). 我有一个numpy ndarray,希望将其绘制在RemoteGraphicsView上(以提高速度,因为它在单独的进程中运行)。 I want to plot a slice of the data but it fails with a TypeError 我想绘制数据切片,但由于TypeError失败

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

The following is a code snippet which demonstrates the problem I have in a larger program. 下面是一个代码片段,演示了我在较大程序中遇到的问题。 As can be seen the data is a numpy.ndarray which is sliced. 可以看出,数据是被切片的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_()

Any help would be much appreciated. 任何帮助将非常感激。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM