写用PySide2和Matplotlib实时动态显示图像的程序
时间: 2024-03-22 08:39:55
浏览: 57
好的,下面是一个使用 PySide2 和 Matplotlib [实时](https://geek.csdn.net/educolumn/020fabea718326d5350ebe5e935f6cdd?spm=1055.2569.3001.10083)动态显示图像的程序示例:
```python
import sys
import random
from PySide2.QtWidgets import QApplication, QMain[window](https://geek.csdn.net/educolumn/03e5a5a554174a38fdfeb8376bd685e2?spm=1055.2569.3001.10083), QVBoxLayout, QWidget
from PySide2.QtCore import Qt
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
from matplotlib.animation import FuncAnimation
class Main[window](https://geek.csdn.net/educolumn/03e5a5a554174a38fdfeb8376bd685e2?spm=1055.2569.3001.10083)(QMain[window](https://geek.csdn.net/educolumn/03e5a5a554174a38fdfeb8376bd685e2?spm=1055.2569.3001.10083)):
def __init__(self):
super().__init__()
# 创建 Matplotlib 图形
self.figure = Figure()
self.canvas = FigureCanvas(self.figure)
self.ax = self.figure.add_subplot(111)
self.ax.set_xlim([0, 10])
self.ax.set_ylim([0, 100])
# 创建 PySide2 布局和[窗口](https://geek.csdn.net/educolumn/00d3d1b467be187bf63895f811603770?spm=1055.2569.3001.10083)
```