pyqt5与matplotlib的完美结合实例-创新互联
具体用到了matplotlib.backends.backend_qt5agg.FigureCanvasQTAgg
创新互联长期为近1000家客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为汉南企业提供专业的成都网站建设、成都做网站,汉南网站改版等技术服务。拥有十载丰富建站经验和众多成功案例,为您定制开发。直接上代码(这里给出的只是一个简单的框架,告诉你怎么去写):
# -*- 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:这里是结合的关键 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()
本文标题:pyqt5与matplotlib的完美结合实例-创新互联
转载注明:http://cdiso.cn/article/dcdddo.html