from PyQt5 import QtWidgets from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas from matplotlib.backends.backend_qt5agg import NavigationToolbar2QTAgg as NavigationToolbar from matplotlib.figure import Figure class MplCanvas(FigureCanvas): def __init__(self): self.fig = Figure() self.ax = self.fig.add_subplot(111) FigureCanvas.__init__(self, self.fig) FigureCanvas.setSizePolicy(self, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding) FigureCanvas.updateGeometry(self) def clear(self): self.ax.clear() self.fig.clear() class MplWidget(QtWidgets.QWidget): def __init__(self, parent = None): QtWidgets.QWidget.__init__(self, parent) self.canvas = MplCanvas() self.vbl = QtWidgets.QVBoxLayout() self.vbl.addWidget(self.canvas) self.setLayout(self.vbl)