I am building an application in PyQt5 that requires a lot of visualization. I use matplotlib and create a custom MplWidget the following way:
import sys
from PyQt5.QtWidgets import QWidget, QMainWindow, QVBoxLayout, QApplication
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg, NavigationToolbar2QT as NavigationToolbar
from matplotlib.figure import Figure
class MplWidget(QWidget):
def __init__(self, parent=None):
QWidget.__init__(self, parent)
self.canvas = FigureCanvasQTAgg(Figure())
vertical_layout = QVBoxLayout()
vertical_layout.addWidget(self.canvas)
self.canvas.axes = self.canvas.figure.add_subplot(111)
self.setLayout(vertical_layout)
self.canvas.toolbar = NavigationToolbar(self.canvas, self)
self.layout().addWidget(self.canvas.toolbar)
self.layout().addWidget(self.canvas)
class MainWindow(QMainWindow):
def __init__(self, *args, **kwargs):
super(MainWindow, self).__init__(*args, **kwargs)
widget = MplWidget()
self.setCentralWidget(widget)
self.show()
app = QApplication(sys.argv)
w = MainWindow()
app.exec_()
It looks like this:
Is there a way to put the navbar inside the figure? There are applications where options (that are contained by the navbar) are invisible until the user hovers the mouse over them, then the navbar appears inside the figure (in the upper left corner for example). This way it does not disturb the figure and takes up less space. I want to do something like that with matplotlib. Can I put widgets on top of each other like this?
