Issue 1:
Bug summary

backend bug in matplotlib==3.6.1 with python3.11

same issue happend when embeding in Qt with PySide6==6.4.0.1

error report

int() argument must be a string, a bytes-like object or a real number, not 'KeyboardModifier'

This is caused by the "The new Enum system" within the release of PySide6, Qt for Python 6.4

See

Qt for python release 6.4

PySide is in the interesting position of being both Qt (with its C++ roots and all that entails) but also distinctly Python. Where possible, we strive to align PySide further with Python conventions and use as many Python features as we can, if they make sense.

Quote below:

The new Enum system

One such area that we tackled now affects enums, which was implemented as bound C++ classes, but now it is updated to leverage Python's own enum mechanism.

Although the new Python enums and the old Shiboken-based ones are compatible with each other, but there are a few differences or restrictions:

Python enums cannot be inherited from each other, whereas Shiboken enums can

Python enums do not allow undefined values, Shiboken enums do

Python enums always need exactly one argument, Shiboken enums have a default zero value

Python enums rarely inherit from int, Shiboken enums always do

You can see that some of these differences are between flags. For example, until now, you could either write

flags = Qt.Alignment()

enum = Qt.AlignmentFlag

or use the enum shortcuts like these:

Qt.AlignLeft = Qt.AlignmentFlag.AlignLeft

Qt.AlignTop = Qt.AlignmentFlag.AlignTop

These shortcuts, and flags no longer exist (officially) from 6.4.0 onwards. Instead, Python has an enum.Flags class, which is a subclass of the enum.Enum class.

If the thought of updating all your code left and right makes you sweat more than an overheated pumpkin spice latte, do not fret, for salvation has a name, and it’s “forgiveness mode”. This transitory mode allows you to continue using the old constructs but translates them internally into the new ones. For example, if you write

flags = Qt.Alignment()

enum = Qt.AlignLeft

item.setForeground(QColor(Qt.green))

flags_type = QPainter.RenderHints

flags = QPainter.RenderHints()

chart_view.setRenderHint(QPainter.Antialiasing)

you get a construct that mimics the following code, which is the recommended way of using flags and enums:

flags = Qt.AlignmentFlag(0)

enum = Qt.AlignmentFlag.AlignLeft

item.setForeground(QColor(Qt.GlobalColor.green))

flags_type = QPainter.RenderHint

flags = QPainter.RenderHint(0)

chart_view.setRenderHint(QPainter.RenderHint.Antialiasing)

With this you can at least initially ignore the difference between old and new enums, as long as the new enums are properties of classes.

Code for reproduction

import matplotlib
print(matplotlib.get_backend())

or

from matplotlib.backends.qt_compat import QtWidgets
from matplotlib.backends.backend_qtagg import (
FigureCanvas, NavigationToolbar2QT as NavigationToolbar)
from matplotlib.figure import Figure

Actual outcome

Traceback (most recent call last):

File "", line 1, in

File "C:\Python311\Lib\site-packages\matplotlib_init_.py", line 1182, in get_backend

return rcParams['backend']

~~~~~~~~^^^^^^^^^^^

File "C:\Python311\Lib\site-packages\matplotlib_init_.py", line 677, in getitem

plt.switch_backend(rcsetup.auto_backend_sentinel)

File "C:\Python311\Lib\site-packages\matplotlib\pyplot.py", line 252, in switch_backend

switch_backend(candidate)

File "C:\Python311\Lib\site-packages\matplotlib\pyplot.py", line 265, in switch_backend

backend_mod = importlib.import_module(

^^^^^^^^^^^^^^^^^^^^^^^^

File "C:\Python311\Lib\importlib_init.py", line 126, in import_module

return _bootstrap._gcd_import(name[level:], package, level)

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "", line 1206, in _gcd_import

File "", line 1178, in _find_and_load

File "", line 1149, in _find_and_load_unlocked

File "", line 690, in _load_unlocked

File "", line 940, in exec_module

File "", line 241, in _call_with_frames_removed

File "C:\Python311\Lib\site-packages\matplotlib\backends\backend_qtagg.py", line 12, in

from .backend_qt import QtCore, QtGui, _BackendQT, FigureCanvasQT

File "C:\Python311\Lib\site-packages\matplotlib\backends\backend_qt.py", line 72, in

_MODIFIER_KEYS = [

^

File "C:\Python311\Lib\site-packages\matplotlib\backends\backend_qt.py", line 73, in

(_to_int(getattr(_enum("QtCore.Qt.KeyboardModifier"), mod)),

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

TypeError: int() argument must be a string, a bytes-like object or a real number, not 'KeyboardModifier'

Expected outcome

QtAgg

Additional information

No response

Operating system

Windows

Matplotlib Version

3.6.1

Matplotlib Backend

error as reported

Python version

3.11

Jupyter version

No response

Installation

pip

Issue 2:
Bug summary

Error while importing matplotlib qt backend.

The version details are as below

matplotlib: 3.6.1

pyside: 6.4.0

python: 3.9.9

on a macOS-M1 machine.

Code for reproduction

from matplotlib.backends.backend_qtagg import NavigationToolbar2QT as NavigationToolbar

Actual outcome

Traceback (most recent call last):

File "", line 1, in

File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/matplotlib/backends/backend_qtagg.py", line 12, in

from .backend_qt import QtCore, QtGui, _BackendQT, FigureCanvasQT

File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/matplotlib/backends/backend_qt.py", line 72, in

_MODIFIER_KEYS = [

File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/matplotlib/backends/backend_qt.py", line 73, in

(_to_int(getattr(_enum("QtCore.Qt.KeyboardModifier"), mod)),

TypeError: int() argument must be a string, a bytes-like object or a number, not 'KeyboardModifier'

Expected outcome

No error!

Additional information

No response

Operating system

OS/X

Matplotlib Version

3.6.1

Matplotlib Backend

MacOSX

Python version

3.9.9

Jupyter version

No response

Installation

pip