Closed
Closed
Copy link
Description
Bug summary
Working with PyQt5, the different import order will make different result.
- If import PyQt5 before import matplotlib, the program will run normally.
- If import PyQt5 after import matplotlib, the program will riase
TypeError
at the method ofQLayout.addWidget
.
Code for reproduction
import sys
# program run correctly, if import PyQt5 here before import matplotlib
# from PyQt5.QtWidgets import QApplication, QVBoxLayout, QWidget
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
# program will raise TypeError, if import import PyQt5 after import matplotlib
from PyQt5.QtWidgets import QApplication, QVBoxLayout, QWidget
if __name__ == "__main__":
app = QApplication(sys.argv)
# init figure
fig = Figure()
fig_canvas = FigureCanvas(fig)
# init widget
layout = QVBoxLayout()
layout.addWidget(fig_canvas) # TypeError here, if import PyQt5 after import matlpotlib
win = QWidget()
win.setLayout(layout)
# run
win.show()
sys.exit(app.exec())
Actual outcome
TypeError
addWidget(self, QWidget, stretch: int = 0, alignment: Union[Qt.Alignment, Qt.AlignmentFlag] = Qt.Alignment()): argument 1 has unexpected type 'FigureCanvasQTAgg'
File "E:\CODE\Python\testroom.py", line 17, in <module>
layout.addWidget(fig_canvas)
Expected outcome
expect no TypeError
Additional information
This Bug will not happen at the version v3.4.x of matplotlib.
Operating system
Windows
Matplotlib Version
3.5.1
Matplotlib Backend
QtAgg
Python version
Python 3.8.10
Installation
pip
Metadata
Metadata
Assignees
Labels
No labels