Skip to content

[Bug]: Oversized Qt5 toolbar icons on macOS Retina display since Matplotlib 3.11 #32217

Description

@JethroHemmann

Bug summary

The navigation toolbar icons are rendered much larger than the toolbar when using Matplotlib 3.11.1 with PyQt5 on a macOS Retina display. The icons are therefore clipped.

The problem does not occur with Matplotlib 3.10.9 in the same Python environment. Only the Matplotlib version was changed for the comparison.

This may be related to the new DPI-aware _IconEngine used by the Qt backend in Matplotlib 3.11.

Code for reproduction

import platform
import sys

import matplotlib
from PyQt5 import QtCore, QtWidgets

matplotlib.use("Qt5Agg")

from matplotlib.backends.backend_qtagg import (
    FigureCanvasQTAgg,
    NavigationToolbar2QT,
)
from matplotlib.figure import Figure


app = QtWidgets.QApplication(sys.argv)

window = QtWidgets.QMainWindow()
window.setWindowTitle("Matplotlib Qt toolbar MWE")

figure = Figure()
canvas = FigureCanvasQTAgg(figure)
toolbar = NavigationToolbar2QT(canvas, window)

axes = figure.subplots()
axes.plot([1, 2, 3], [1, 4, 2], marker="o")

contents = QtWidgets.QWidget()
layout = QtWidgets.QVBoxLayout(contents)
layout.addWidget(toolbar)
layout.addWidget(canvas)
window.setCentralWidget(contents)

window.resize(900, 600)
window.show()

screen = app.primaryScreen()
print("Matplotlib:", matplotlib.__version__)
print("Backend:", matplotlib.get_backend())
print("Python:", sys.version.split()[0])
print("Architecture:", platform.machine())
print("macOS:", platform.mac_ver()[0])
print("PyQt:", QtCore.PYQT_VERSION_STR)
print("Qt runtime:", QtCore.qVersion())
print("Qt used to build PyQt:", QtCore.QT_VERSION_STR)
print("Device-pixel ratio:", screen.devicePixelRatio())
print("Logical DPI:", screen.logicalDotsPerInch())
print("Physical DPI:", screen.physicalDotsPerInch())
print("Toolbar icon size:", toolbar.iconSize())

raise SystemExit(app.exec())

Actual outcome

With Matplotlib 3.11.1, the toolbar icons are approximately twice their intended linear size and are clipped by the toolbar.
The toolbar itself reports an icon size of 32 × 32.

Code output:

Python: 3.12.4
Architecture: arm64
macOS: 26.5.2
Matplotlib: 3.11.1
Backend: Qt5Agg
PyQt: 5.15.11
Qt runtime: 5.15.19
Qt used to build PyQt: 5.15.14
Screen device-pixel ratio: 2.0
Screen logical DPI: 72.0
Screen physical DPI: 127.5
Toolbar icon size: 32x32
Image

Expected outcome

The icons should fit inside the toolbar, as they do with Matplotlib 3.10.9.

Code output:

Python: 3.12.4
Architecture: arm64
macOS: 26.5.2
Matplotlib: 3.10.9
Backend: Qt5Agg
PyQt: 5.15.11
Qt runtime: 5.15.19
Qt used to build PyQt: 5.15.14
Screen device-pixel ratio: 2.0
Screen logical DPI: 72.0
Screen physical DPI: 127.5
Toolbar icon size: 32x32
Image

Additional information

The comparison was performed by installing Matplotlib 3.10.9 and 3.11.1 successively into the same virtual environment. Python, PyQt5, Qt, and the display configuration remained unchanged.

Operating system

macOS 26.5.2

Matplotlib Version

3.11.1

Matplotlib Backend

Qt5Agg

Python version

3.12.4

Jupyter version

No response

Installation

pip

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions