具體用到了matplotlib.backends.backend_qt5agg.FigureCanvasQTAgg
創(chuàng)新互聯(lián)長期為近1000家客戶提供的網(wǎng)站建設(shè)服務(wù),團(tuán)隊從業(yè)經(jīng)驗10年,關(guān)注不同地域、不同群體,并針對不同對象提供差異化的產(chǎn)品和服務(wù);打造開放共贏平臺,與合作伙伴共同營造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為漢南企業(yè)提供專業(yè)的成都網(wǎng)站建設(shè)、成都做網(wǎng)站,漢南網(wǎng)站改版等技術(shù)服務(wù)。擁有十載豐富建站經(jīng)驗和眾多成功案例,為您定制開發(fā)。直接上代碼(這里給出的只是一個簡單的框架,告訴你怎么去寫):
# -*- coding: utf-8 -*- ''' TODO:LQD ''' import sys import numpy as np import matplotlib.pyplot as plt from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FC from PyQt5.QtWidgets import QApplication, QPushButton, QMainWindow, QVBoxLayout, QWidget class QtDraw(QMainWindow): flag_btn_start = True def __init__(self): super(QtDraw, self).__init__() self.init_ui() def init_ui(self): self.resize(800, 600) self.setWindowTitle('PyQt5 Draw') # TODO:這里是結(jié)合的關(guān)鍵 self.fig = plt.Figure() self.canvas = FC(self.fig) self.btn_start = QPushButton(self) self.btn_start.setText('draw') self.btn_start.clicked.connect(self.slot_btn_start) widget = QWidget() layout = QVBoxLayout() layout.addWidget(self.canvas) layout.addWidget(self.btn_start) widget.setLayout(layout) self.setCentralWidget(widget) def slot_btn_start(self): try: ax = self.fig.add_subplot(111) x = np.linspace(0, 100, 100) y = np.random.random(100) ax.cla() # TODO:刪除原圖,讓畫布上只有新的一次的圖 ax.plot(x, y) self.canvas.draw() # TODO:這里開始繪制 except Exception as e: print(e) def ui_main(): app = QApplication(sys.argv) w = QtDraw() w.show() sys.exit(app.exec_()) if __name__ == '__main__': ui_main()