Mathtext rendering fails with Matplotlib 3.11: glyph tuples now contain six fields

Offen
#66 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
72/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
cpp, matplotlib, python
Bereich
backend

Rechercherichtung

Start by tracing how mplcairo handles MathTextParser("path").parse(...).glyphs and compare its expected tuples with Matplotlib 3.11's six-field tuples. Use the reproducer to confirm the rendering failure, then check both canvas drawing and MultiPage PDF output. Done means the mathtext annotation renders and multipage saving succeeds with Matplotlib 3.11.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

Bug summary

Rendering a figure containing mathtext with mplcairo 0.6.1 and
Matplotlib 3.11.2 fails with a C++ type-casting error. This also
affects saving such figures with mplcairo.multipage.MultiPage.

Reproducer

import matplotlib

matplotlib.use("module://mplcairo.base")

import matplotlib.pyplot as plt

fig, ax = plt.subplots()
ax.plot([1, 2])
ax.annotate(r"$\sigma_f=1.4\times 10^{-8}$", (1, 1))
fig.canvas.draw()

Actual result

RuntimeError: Unable to cast Python instance of type <class 'tuple'>
to C++ type '?' (#define PYBIND11_DETAILED_ERROR_MESSAGES or
compile in debug mode for details)

Expected result

The figure renders with the mathtext annotation.

Likely cause

Matplotlib 3.11 added a glyph index to each tuple in
MathTextParser("path").parse(...).glyphs. The tuples now contain:

(font, fontsize, character_code, glyph_index, x, y)

The mplcairo renderer appears to cast each tuple to the previous
five-field form. Matplotlib documents the change here:

https://matplotlib.org/stable/api/prev_api_changes/api_changes_3.11.0.html#mathtext-vectorparse-now-includes-glyph-indices

As a local experiment, adapting the parser result to remove the added
glyph-index field allowed both canvas rendering and multipage PDF
output to complete. This was a compatibility experiment, not a
tested upstream patch.

Environment

Python: 3.15.2
Matplotlib: 3.11.2
mplcairo: 0.6.1
Fedora Linux 45

Vorherrschende Sprache
C++
Sterne
120
Forks
23
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Entwicklungsumgebung

Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus matplotlib/mplcairo

Alle Issues in matplotlib/mplcairo

Ähnliche Issues

Weitere Issues zu C++

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.