from PyQt5.QtWidgets import *
import pyqtgraph as pg
import sysclass MainWindow(QWidget):def __init__(self):super().__init__()self.setWindowTitle('pyqtgraph作图示例')# 创建 PlotWidget 对象self.pw = pg.PlotWidget()# 设置图表标题self.pw.setTitle("气温趋势",color='#008080',size='12pt')# 设置上下左右的labelself.pw.setLabel("left","气温(摄氏度)")self.pw.setLabel("bottom","时间")# 背景色改为白色self.pw.setBackground('w')hour = [1,2,3,4,5,6,7,8,9,10]temperature = [30,32,34,32,33,31,29,32,35,45]# hour 和 temperature 分别是 : x, y 轴上的值self.pw.plot(hour,temperature,pen=pg.mkPen('b') # 线条颜色)# 创建其他Qt控件okButton = QPushButton("OK")lineEdit = QLineEdit('点击信息')# 水平layout里面放 edit 和 buttonhbox = QHBoxLayout()hbox.addWidget(lineEdit)hbox.addWidget(okButton)# 垂直layout里面放 pyqtgraph图表控件 和 前面的水平layoutvbox = QVBoxLayout()vbox.addWidget(self.pw)vbox.addLayout(hbox)# 设置全局layoutself.setLayout(vbox)if __name__ == '__main__':app = QApplication(sys.argv)main = MainWindow()main.show()app.exec_()