我尝试了pg.close(),但是没有用,在手册中找不到。我以循环方式生成图,因此我想在每个循环结束时将其全部关闭(取而代之的是,它将弹出一个新窗口,直到我的计算机崩溃为止)。
我正在一个项目中,我将不得不分析来自设备的信号。我有一个图书馆在工作,可以从设备中获取数据。到目前为止,我正在收集数据,然后将其绘制出来。我对构建实时数据监控器感兴趣,该监控器可以实时绘制图形。搜索后,我发现PyQtGraph非常适合该任务。我对Qt不熟悉,因此我正在寻找可以根据需要进行修改的示例。PyQtGraph文档中提供的一些示例可实时更新绘图,但我需要一个实时监控器(Live Monitor),该图形在不断接收数据的同时向右移动。
如果它像一个已知的连续函数,我可以更新输入x - w*t与t暂且以获得波向右移动。但这是离散的数据,因此我不确定如何使用PyQtGraph使其工作。因此,如果有人可以提出一些建议,那就太好了。
截至目前,这就是我所拥有的
码
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)
Run Code Online (Sandbox Code Playgroud)
这是每2秒更新一次数据,但是我希望它向右移动。
我有一个与以下问题非常相似的应用程序:画半条无限线?
我想有多个阈值的无限线。
问题中提供的解决方案是一个很好的起点:https : //stackoverflow.com/a/37836348/7163293
我试图通过在中修改movable属性__init__并添加一个setMovable方法来使线可移动,就像在source中的源代码一样:
from pyqtgraph.Qt import QtGui
import numpy as np
import pyqtgraph as pg
class InfiniteLineWithBreak(pg.GraphicsObject):
def __init__(self, changeX, levelsY, pen=None):
pg.GraphicsObject.__init__(self)
self.changeX = changeX
self.levelsY = levelsY
self.maxRange = [None, None]
self.moving = False
self.movable = True
self.setMovable(self.movable)
self.mouseHovering = False
pen = (200, 200, 100)
self.setPen(pen)
self.setHoverPen(color=(255,0,0), width=self.pen.width())
self.currentPen = self.pen
def setMovable(self, m):
"""Set whether the line is movable by the user."""
self.movable = …Run Code Online (Sandbox Code Playgroud) 我必须绘制 3 条从传感器读取的数据更新曲线。当我只使用一条曲线时,更新图非常快,但是当我尝试绘制它们时,它们中的每一个都非常慢。我使用的代码如下:
#!/usr/bin/python
from pyqtgraph.Qt import QtGui, QtCore
import pyqtgraph as pg
import time
import numpy as np
app = QtGui.QApplication([])
win = pg.GraphicsWindow()
p1 = win.addPlot()
p2 = win.addPlot()
p3 = win.addPlot()
curve1 = p1.plot()
curve2 = p2.plot()
curve3 = p3.plot()
readData = [0.0, 0.0, 0.0]
y1=[0.0]
y2=[0.0]
y3=[0.0]
temp = [0.0]
start = time.time()
def update():
global curve1, curve2, curve3
t = time.time()-start # measure of time as x-coordinate
readData= readfun() #function that reads data from the …Run Code Online (Sandbox Code Playgroud) 我目前有一个ImageView显示 Dicom 图像,但我不想在侧面显示该直方图。如果可能,将这两个按钮移到另一个位置。我怎样才能做到这一点?
我试图在 pyqtgraph 中使用 PlotCurveItem 创建的两条曲线之间进行填充。
phigh = self.p2.addItem(pg.PlotCurveItem(x, y, pen = 'k'))
plow = self.p2.addItem(pg.PlotCurveItem(x, yy, pen = 'k'))
pfill = pg.FillBetweenItem(phigh, plow, brush = br)
self.p2.addItem(pfill)
Run Code Online (Sandbox Code Playgroud)
曲线项目绘制正确,但没有填充。
我在保持 gridLayout 中所有元素的大小时遇到了一些麻烦。
有时,在我更新绘图数据(宽度和高度)后,内部小部件会完全改变大小,尤其是在最大化/最小化或更改窗口大小之后:
我希望实现的是无论窗口的尺寸如何,尺寸都保持均匀分布:
这是我为填充网格而编写的内容的摘要,以及我如何更新 CSS 以使边框更改颜色。我注意到,如果我不更改 CSS,那么这个问题就不明显了。
class ResultsViewer(QtGui.QWidget):
plots = {} #the currently displayed plot widgets
curves = {} #the currently displayed data that store the points
def __init__(self):
super(ResultsViewer, self).__init__()
self.win = QtGui.QMainWindow()
self.win.setCentralWidget(self)
self.win.resize(800, 250)
self.win.setWindowTitle("Cavity Results Viewer")
self.grid = QtGui.QGridLayout(self)
self.win.setWindowFlags(self.win.windowFlags() | QtCore.Qt.WindowStaysOnTopHint)
def reset_indicators(self):
for plot in self.plots.keys():
self.plots[plot].setStyleSheet("""
border-top: 5px solid rgba(0,0,0,0);
border-radius: 12px;
""")
def set_indicator_border_color(self, cavnum, result):
color = "lime" if result['decision'] else "red"
self.plots[cavnum].setStyleSheet(""" …Run Code Online (Sandbox Code Playgroud) 我想将 PyQtGraph PlotWidget 实现到 PySide2 应用程序中。使用 PyQt5 一切正常。使用 PySide2 我得到底部显示的错误。我已经发现,有一些工作正在进行中,但似乎也有一些人设法使这项工作正常进行。但是,我还做不到。我使用的是 Pyqtgraph 0.10 而不是开发者分支。我要不要改变?我需要做什么?
from PySide2.QtWidgets import QApplication, QMainWindow, QGraphicsView, QVBoxLayout, QWidget
import sys
import pyqtgraph as pg
class WdgPlot(QWidget):
def __init__(self, parent=None):
super(WdgPlot, self).__init__(parent)
self.layout = QVBoxLayout(self)
self.pw = pg.PlotWidget(self)
self.pw.plot([1,2,3,4])
self.pw.show()
self.layout.addWidget(self.pw)
self.setLayout(self.layout)
if __name__ == '__main__':
app = QApplication(sys.argv)
w = WdgPlot()
w.show()
sys.exit(app.exec_())
Run Code Online (Sandbox Code Playgroud)
错误:
QtGui.QGraphicsView.__init__(self, parent)
TypeError: arguments did not match any overloaded call:
QGraphicsView(parent: QWidget = None): argument 1 has unexpected type 'WdgPlot'
QGraphicsView(QGraphicsScene, parent: QWidget …Run Code Online (Sandbox Code Playgroud) 我正在尝试设置 pyqtgraph.PlotWidget 绘图区域的轴样式。我在用着:
font = QFont()
font.setPointSize(14)
font.setBold(True)
font.setWeight(75)
myPlotWidget.getAxis('left').setPen('b')
myPlotWidget.getAxis('left').setFont(font)
Run Code Online (Sandbox Code Playgroud)
我不明白为什么刻度标签颜色不是蓝色,而轴、网格和轴标签是蓝色。