| import sys import numpy as np from PyQt5.QtGui import * from PyQt5.QtCore import * from PyQt5.QtWidgets import *   import pyqtgraph as pg   from ui_demo02 import Ui_MainWindow     class GraphDemowWindow(QMainWindow, Ui_MainWindow):     def __init__(self, parent=None):         super(GraphDemowWindow, self).__init__(parent)         self.setupUi(self)           pg.setConfigOptions(antialias=True) # 设置开启抗锯齿           self.drawGraphicsLayoutWidget()         self.drawPoltWidget()       # 在QWidget控件提升为pyqtgraph.GraphicsLayoutWidget类型的控件上画波形     def drawGraphicsLayoutWidget(self):         # pyqtgraph.GraphicsLayoutWidget 支持的方法有:         # ['nextRow', 'nextCol', 'nextColumn', 'addPlot', 'addViewBox', 'addItem', 'getItem', 'addLayout', 'addLabel', 'removeItem', 'itemIndex', 'clear']         self.graphicsLayout.clear() # 清除         plt1 = self.graphicsLayout.addPlot(y=np.random.normal(size=1000), title="温度")         plt2 = self.graphicsLayout.addPlot(y=np.random.normal(size=500), title="湿度")         self.graphicsLayout.nextRow() # 图像坐标换行         plt3 = self.graphicsLayout.addPlot(y=np.random.normal(size=800), title="光照度")         plt4 = self.graphicsLayout.addPlot(y=np.random.normal(size=800), title="紫外线强度")         # 在QWidget控件提升为pyqtgraph.PlotWidget类型的控件上画波形     def drawPoltWidget(self):         # pyqtgraph.PlotWidget 支持的方法有:         # ['addItem', 'removeItem', 'autoRange', 'clear', 'setAxisItems', 'setXRange',         #           'setYRange', 'setRange', 'setAspectLocked', 'setMouseEnabled',         #           'setXLink', 'setYLink', 'enableAutoRange', 'disableAutoRange',         #           'setLimits', 'register', 'unregister', 'viewRect']                     # pen = pg.mkPen(255, 0, 0)         # pen = pg.mkPen("#ff0000")         # pen = pg.mkPen(color='r', width=3)         pen = pg.mkPen({'color':'0F0', 'width':1})         plt1 = self.graphPlot.plot(np.random.normal(size=100), pen=pen,  symbolBrush=(255, 0, 0), symbolPen=(0, 255, 0))           pen2 = pg.mkPen(color="F00", width=1)         plt2 = self.graphPlot.plot(np.random.normal(size=50), pen=pen2,  symbolBrush=(0, 255, 0), symbolPen=(255, 0, 0))           self.graphPlot.setAntialiasing(True)         self.graphPlot.setBackground("#ffffff")                         if __name__ == "__main__":     app = QApplication(sys.argv)     win = GraphDemowWindow()     win.show()     sys.exit(app.exec_()) |