Python-PyQt版面配置與嵌入即時動態圖
控制板讀到的訊號需要即時顯示,因此我用PyQT寫了個GUI範例,並且能即時更新圖表,畫圖的部分採用matplotlib。 上面圖表就是程式碼會顯示的即時圖,右邊是即時產生sin與cos值,左邊是cos、sin分別在x,y軸產生出來的圖形。 import sys import PyQt5 import time import numpy as np from matplotlib.backends.qt_compat import QtCore, QtWidgets, is_pyqt5 if is_pyqt5(): from matplotlib.backends.backend_qt5agg import ( FigureCanvas, NavigationToolbar2QT as NavigationToolbar) else: from matplotlib.backends.backend_qt4agg import ( FigureCanvas, NavigationToolbar2QT as NavigationToolbar) from matplotlib.figure import Figure class ApplicationWindow(QtWidgets.QMainWindow): def __init__(self): super().__init__() self._main = QtWidgets.QWidget() self.setCentralWidget(self._main) layout = QtWidgets.QGridLayout(self._main) #新增圖表 dynamic_canvas_total = FigureCanvas(Figure(figsize=(5, 3))) dynamic_canvas_x = FigureCanvas(Figure(figsize=(5, 3))) dynamic_canvas_y = FigureCanvas(Figure(figsize=(5, 3))) ...