gpt4 book ai didi

python - PyQt5 Pyqtgraph 离散图

转载 作者:太空宇宙 更新时间:2023-11-03 21:35:10 25 4
gpt4 key购买 nike

目前,对于这个项目,我正在使用 matplolib 来追踪我的情节。尽管如此,我希望在 pyqtgraph ( Pyqt5) 进行转换。我没有找到如何使用 pyqtgraph 跟踪 FFT 的离散图,与图片相同。你有主意吗?

enter image description here

最佳答案

您可以创建一个在其中绘制垂直线的项目:

from pyqtgraph.Qt import QtGui, QtCore
import pyqtgraph as pg

class LinePlot(pg.GraphicsObject):
def __init__(self, data):
super(LinePlot, self).__init__()
self._data = []
self.setData(data)

def setData(self, data):
self._data = data
self.generate()

def generate(self):
self.picture = QtGui.QPicture()
p = QtGui.QPainter(self.picture)
p.setPen(pg.mkPen('r', width=2))
for (t, v) in self._data:
if v != 0:
p.drawLine(QtCore.QPointF(t, 0), QtCore.QPointF(t, v))

def paint(self, p, *args):
p.drawPicture(0, 0, self.picture)

def boundingRect(self):
return QtCore.QRectF(self.picture.boundingRect())

if __name__ == '__main__':
import sys
import random

app = QtGui.QApplication(sys.argv)
w = QtGui.QMainWindow()
view = pg.GraphicsLayoutWidget()
w.setCentralWidget(view)
plot = view.addPlot()
vals = [(i, random.randint(0, 255)) for i in range(30)]
plot.addItem(LinePlot(vals))
w.show()
sys.exit(app.exec_())

enter image description here

关于python - PyQt5 Pyqtgraph 离散图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53283831/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com