Skip to content Skip to sidebar Skip to footer

Matplotlib In Second Window Pyqt5

I wish to plot a matplotlib graph in a second window when a button is clicked in the main window. Using https://matplotlib.org/examples/user_interfaces/embedding_in_qt4.html , whic

Solution 1:

In your case the main_widget does not have the same size as the QMainWindow so if you change the size with self.SW.resize(300,300) it will not change the size of self.main_widget, the solution would be to use a layout but in the case of QMainWindow it is not correct to do so since this has a custom layout that should not be modified:

enter image description here

The solution in the case of QMainWindow is always to establish a centralwidget, in your case it could be using the self.main_widget:

classSecondWindow(QMainWindow):def__init__(self):
         super(SecondWindow, self).__init__()
         self.main_widget = QtWidgets.QWidget()
         self.setCentralWidget(self.main_widget)

         layout = QtWidgets.QVBoxLayout(self.main_widget)
         sc = MyMplCanvas(self.main_widget, width = 300, height = 300)
         layout.addWidget(sc)

Post a Comment for "Matplotlib In Second Window Pyqt5"