matplotlib的基础类figure相当于一个View窗口类(实际上,每一个figure是由更底层canvas来控制的,大概有点类似CAD的layers层的概念),是一个可绘制显示图形的View区域,也称画布(figure)
在matplotlib中留与Pyqt 5的接口:
matplotlib.use("Qt5Agg") # 声明使用QT5
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg
而matplotlib.figure类初始化一张画布:
每个axes相当于一个子图形对象,可以图形化一组关联数据的特定关系,称为plot
绑定QT5控件: QtWidgets.QGraphicsView,实现在QGraphicsView显示matplotlib.figure
(1)需导入:
import matplotlib
matplotlib.use("Qt5Agg") # 声明使用QT5
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure as MPL_Figure
(2)自定义绘图类:
class FigureView(FigureCanvas):
def __init__(self):
self.figCanvas = MPL_Figure()
super(FigureView,self).__init__(self.figCanvas)
pass
(3)绑定:
figview=FigureView()
scene=QGraphicsScene()
scene.addWidget(cFigView)
self.graphicsView.setScene(scene)
本文用图参考了:https://blog.csdn.net/bluishglc/article/details/128553539