近期解决了:python plt与Qt的集成
需要导入的控件
from matplotlib.backends.backend_qt5 import NavigationToolbar2QT
from matplotlib.figure import Figure
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
一、QT:需提前定义好
graph_view=QGraphicsView()
graph_scen=QGraphicsScene()
与tableView()与tableModel关系类似可以查手册解决问题
二、必须先实例化:类
class MyFigureCanvas(FigureCanvas):
def init(self):
# 画布上初始化⼀个图像
self.figure = Figure()
super().init(self.figure)
三、操作
1、将绘图控件实例化:fig=MyFigureCanvas()
2、添加画布:ax=fig.figure.add_subplot()
3、在画布当中绘制:ax.plot(x,y,color=’red’)
4、在场景中增加实例化的控件:graph_scen.addWidget(fig)
5、将场景设置到View当中:graph_view.setSence(graph_scen)
最终效果:

至此:强大的库matplotlib已经加入到了控件当中,还可以实现菜单栏、修改数据的功能。
其它操作
增加操作界面
将导入的NavigationToolbar2QT加入到layout当中:
tool_bar=NavigationToolbar2QT(fig,widget)
glayout.addWidget(tool_bar)

以上为加入控件后的图形
注:不能在Scene当中添加,报错:QGraphicsProxyWidget::setWidget: cannot embed widget 0x60000374b170 which is not a toplevel widget, and is not a child of an embedded widget
五、重要功能:
清除图形
ax.cla()
绘制图形
ax.plot(data)
fig.draw()
六、画布清除功
garph_scen.clear():此功能慎用,使用后需要重新建立所有对像,重画所有的图形