实时数据监视器:PyQtGraph [英] Live Data Monitor: PyQtGraph

查看:108
本文介绍了实时数据监视器:PyQtGraph的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个项目,我必须分析来自设备的信号.我有一个库可以从设备中获取数据.截至目前,我正在收集数据,然后绘制它.我对构建一个可以实时绘制图形的实时数据监视器很感兴趣.经过搜索,我发现 PyQtGraph 非常适合这项任务.我不熟悉 Qt,所以我正在寻找可以根据我的需要进行修改的示例.PyQtGraph 文档中给出的一些示例实时更新绘图,但我需要像实时监视器这样的东西 - 图形在不断接收数据时向右移动.

I am working on a project where I will have to analyse signals coming from a device. I have a library working which gets me data from the device. As of now, I am collecting the data and then plotting it. I am interested in building a live data monitor which can plot a graph in real time. Upon searching, I figured out PyQtGraph is ideal for the task. I am not familiar with Qt, so I am looking for examples which I can modify to my needs. Some examples given in PyQtGraph docs update the plot real-time BUT I need something like a live monitor- where the graph is moving towards the right as it keeps receiving data.

如果它类似于一个已知的连续函数,我可以更新输入 x - w*tt 是时间,以便让波浪朝着正确的.但这是离散数据,所以我不确定如何使用 PyQtGraph 使其工作.因此,如果有人可以就如何去做提供一些指导,那就太好了.

If it it something like a known continuous function, I can update the input x - w*t with t being the time so as to get the wave moving towards right. But this is discrete data, so I am not sure about how to get it working using PyQtGraph. So it would be great if someone could give some pointers on how to go about.

到目前为止,这是我所拥有的

As of now this is what I have

代码

app = QtGui.QApplication([])
#mw = QtGui.QMainWindow()
#mw.resize(800,800)

win = pg.GraphicsWindow(title="Basic plotting examples")
win.resize(1000,600)
win.setWindowTitle('pyqtgraph example: Plotting')

# Enable antialiasing for prettier plots
pg.setConfigOptions(antialias=True)

p6 = win.addPlot(title="Updating plot")
curve = p6.plot(pen='r')
X_axis = numpy.linspace(0,100,12800)
#'data' is my required y_axis containing 12800 values
ydata = np.array_split(data,50)
xdata = np.array_split(X_axis,50)
ptr = 0
def update():
    global curve, data, ptr, p6
    curve.setData(xdata[ptr%50],ydata[ptr%50])
    ptr += 1
timer = QtCore.QTimer()
timer.timeout.connect(update)
timer.start(1000)

这是每隔 2 秒更新一次数据,但我希望它向右移动.

This is updating the data for every 2-second interval, but I want it to move towards the right.

推荐答案

要使情节滚动,您有三个选择:

To make a plot scroll, you have three options:

  1. 滚动原始数据并重新绘制(参见 numpy.roll)

curve = plotItem.plot(data)
data = np.roll(data, 1)  # scroll data
curve.setData(data)      # re-plot

  • 移动绘图曲线,使其在视图中滑动:

  • Move the plot curve so that it slides across the view:

    curve = plotItem.plot(data)
    curve.setPos(x, 0)  # Move the curve
    

  • 移动视图区域,使绘图曲线看起来像滚动

  • Move the view region such that the plot curve appears to scroll

    curve = plotItem.plot(data)
    plotItem.setXRange(x1, x2)  # Move the view
    

  • 滚动图示例(目前仅在开发版)演示了其中的每一个:

    The scrolling-plots example (currently only in the development version) demonstrates each of these:

    这篇关于实时数据监视器:PyQtGraph的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆