Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Bug]: Working with PyQt5, the different import order will make different result. #21998

Copy link
Copy link
Closed
@MusYi

Description

@MusYi
Issue body actions

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 of QLayout.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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.