71e1ea34fd
PR for adding Qt6 support to matplotlib indicates that both Qt5 and Qt6 will use backend_qt5agg
40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
from ..Qt import QtGui, QtCore, QT_LIB
|
|
import matplotlib
|
|
|
|
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
|
|
from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar
|
|
|
|
from matplotlib.figure import Figure
|
|
|
|
class MatplotlibWidget(QtGui.QWidget):
|
|
"""
|
|
Implements a Matplotlib figure inside a QWidget.
|
|
Use getFigure() and redraw() to interact with matplotlib.
|
|
|
|
Example::
|
|
|
|
mw = MatplotlibWidget()
|
|
subplot = mw.getFigure().add_subplot(111)
|
|
subplot.plot(x,y)
|
|
mw.draw()
|
|
"""
|
|
|
|
def __init__(self, size=(5.0, 4.0), dpi=100):
|
|
QtGui.QWidget.__init__(self)
|
|
self.fig = Figure(size, dpi=dpi)
|
|
self.canvas = FigureCanvas(self.fig)
|
|
self.canvas.setParent(self)
|
|
self.toolbar = NavigationToolbar(self.canvas, self)
|
|
|
|
self.vbox = QtGui.QVBoxLayout()
|
|
self.vbox.addWidget(self.toolbar)
|
|
self.vbox.addWidget(self.canvas)
|
|
|
|
self.setLayout(self.vbox)
|
|
|
|
def getFigure(self):
|
|
return self.fig
|
|
|
|
def draw(self):
|
|
self.canvas.draw()
|