Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Description
Bug summary
I use matplotlib + PyQt5. The figure is placed inside a QSplitter (a standard Qt widget that consists of several vertical or horizontal parts which the handles between those parts can resize). When a part of QSplitter shrinks to a zero size it automatically resizes the widget it contains. I already had an issue with this (#17093) but now I have a new one.
When there are other widgets in the same splitter part with a figure the figure becomes negatively sized.
Here a splitter consists of two parts: the top one with one button and the bottom one with a figure and a button in a vertical layout. When I pull the split line all the way down I get an exception that the figure has a negative size.
Code for reproduction
importsysfromPyQt5.QtWidgetsimportQMainWindow,QApplication,QVBoxLayoutfrommatplotlib.backends.backend_qt5aggimportFigureCanvasQTAggasFigureCanvasfrommatplotlib.figureimportFigurefromPyQt5importQtCore,QtGui,QtWidgetsclassUi_MainWindow(object):defsetupUi(self,MainWindow):MainWindow.setObjectName("MainWindow")MainWindow.resize(800,600)self.centralwidget=QtWidgets.QWidget(MainWindow)self.centralwidget.setObjectName("centralwidget")self.gridLayout=QtWidgets.QGridLayout(self.centralwidget)self.gridLayout.setObjectName("gridLayout")self.splitter=QtWidgets.QSplitter(self.centralwidget)self.splitter.setOrientation(QtCore.Qt.Vertical)self.splitter.setObjectName("splitter")self.pushButton=QtWidgets.QPushButton(self.splitter)self.pushButton.setObjectName("pushButton")self.widget=QtWidgets.QWidget(self.splitter)self.widget.setObjectName("widget")self.verticalLayout=QtWidgets.QVBoxLayout(self.widget)self.verticalLayout.setContentsMargins(0,0,0,0)self.verticalLayout.setObjectName("verticalLayout")self.plot=QtWidgets.QWidget(self.widget)self.plot.setObjectName("plot")self.verticalLayout.addWidget(self.plot)self.pushButton_2=QtWidgets.QPushButton(self.widget)self.pushButton_2.setObjectName("pushButton_2")self.verticalLayout.addWidget(self.pushButton_2)self.gridLayout.addWidget(self.splitter,0,0,1,1)MainWindow.setCentralWidget(self.centralwidget)self.menubar=QtWidgets.QMenuBar(MainWindow)self.menubar.setGeometry(QtCore.QRect(0,0,800,32))self.menubar.setObjectName("menubar")MainWindow.setMenuBar(self.menubar)self.statusbar=QtWidgets.QStatusBar(MainWindow)self.statusbar.setObjectName("statusbar")MainWindow.setStatusBar(self.statusbar)self.retranslateUi(MainWindow)QtCore.QMetaObject.connectSlotsByName(MainWindow)defretranslateUi(self,MainWindow):_translate=QtCore.QCoreApplication.translateMainWindow.setWindowTitle(_translate("MainWindow","MainWindow"))self.pushButton.setText(_translate("MainWindow","PUSH"))self.pushButton_2.setText(_translate("MainWindow","PUSH2"))classMainWindow(QMainWindow):def__init__(self,*args):super().__init__(*args)self.ui=Ui_MainWindow()self.ui.setupUi(self)self.figure=Figure()self.canvas=FigureCanvas(self.figure)layout=QVBoxLayout()layout.addWidget(self.canvas)self.ui.plot.setLayout(layout)app=QApplication(sys.argv)mw=MainWindow()mw.show()app.exec()
Actual outcome
ValueError: figure size must be positive finite not [ 7.76 -0.06]
Expected outcome
Not seeing an exception.
Additional information
No response
Operating system
Kubuntu 22.04
Matplotlib Version
3.7.1
Matplotlib Backend
QtAgg
Python version
Python 3.10.6
Jupyter version
No response
Installation
pip