【无标题】pyqtgraph 使用
创始人
2025-05-28 18:39:40

1.安装

pip install pyqtgraph 

2.designer 添加PlotWidget

操作步骤如下:

  1. Designer中,创建一个QGraphicsView小部件(“Graphics View”类别下的“Display Widgets”)
  2. 用鼠标右键单击QGraphicsView并选择““Promote To…”
  3. 在“Promoted calss name”下,输入您希望使用的类名称(“PlotWidget”,“GraphicsLayoutWidget”等)。这里我选的是PlotWidget
  4. 在“Header file”下,输入“pyqtgraph”
  5. 点击“Add”,然后点击“Promote”

3.PlotWidget使用

# test1.pyfrom PyQt5 import QtCore, QtGui, QtWidgets
from pyqtgraph import PlotWidgetclass Ui_Form(object):def setupUi(self, Form):Form.setObjectName("Form")Form.resize(965, 783)self.plotWidget = PlotWidget(Form)self.plotWidget.setGeometry(QtCore.QRect(60, 100, 851, 521))self.plotWidget.setStyleSheet("")self.plotWidget.setObjectName("plotWidget")self.retranslateUi(Form)QtCore.QMetaObject.connectSlotsByName(Form)def retranslateUi(self, Form):_translate = QtCore.QCoreApplication.translateForm.setWindowTitle(_translate("Form", "Form"))
from PyQt5.QtWidgets import QWidget, QMainWindow, QApplication
from test1 import Ui_Form
from constant import x, y, bclass TestUI(QWidget, Ui_Form):def __init__(self):super(TestUI, self).__init__()self.setupUi(self)# # 设置背景# self.plotWidget.setBackground('w')# # 增加图例# # (1,2)中的2代表有2条线,系统会自动创建两种不同的颜色,1就代表这是第一条线# self.plotWidget.addLegend()# self.plotWidget.plot(x, y, pen=(1, 2), name='训练集')# self.plotWidget.plot(x, b, pen=(2, 2), name='测试集')# # 设置X轴,Y轴# self.plotWidget.setLabel('left', 'LOSS')# self.plotWidget.setLabel('bottom', 'epoch')# # 设置网格# self.plotWidget.showGrid(x=True, y=True)# 设置背景self.plotWidget.setBackground('w')# 增加图例# (1,2)中的2代表有2条线,系统会自动创建两种不同的颜色,1就代表这是第一条线self.plotWidget.addLegend()curve1 = self.plotWidget.plot(pen=(1, 2), name='训练集')curve2 = self.plotWidget.plot(pen=(2, 2), name='测试集')# 设置X轴,Y轴self.plotWidget.setLabel('left', 'LOSS')self.plotWidget.setLabel('bottom', 'epoch')# 设置网格self.plotWidget.showGrid(x=True, y=True)curve1.setData(x, y)curve2.setData(x, b)if __name__ == "__main__":import sysapp = QApplication(sys.argv)ui = TestUI()ui.show()sys.exit(app.exec_())

相关内容

热门资讯

袁小饺获“年度先锋品牌”,以创... 近日,在美团第八届餐饮产业大会上,袁小饺凭借在产品创新、数字化运营及产业赋能等领域的突出表现,斩获“...
原创 铁... 哈喽大家好,今天老张带大家聊聊最近全球铁矿圈接连爆出两个大瓜,剧情反转比短视频里的狗血剧还刺激,主打...
随着波动性上升,黄金的吸引力是... 来源:金十数据 世界黄金协会分析师回应市场关切,指出黄金波动率仍与长期平均水平一致。他们认为,在股...
原创 帮... 最近好多朋友追着问我,帮主,海南封关到底是啥意思?是不是以后去海南得办通行证,跟去港澳一样?还有人说...
日本30年期国债收益率上涨1.... 11月12日消息,日本30年期国债收益率上涨1.5个基点至2.26%,创7月4日以来新高。