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

未關閉
#66 2 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
3/5
預估耗時
1-2 天
新手友好度
72/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
cpp, matplotlib, python
領域
backend

研究方向

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.

由索引模型根據 Issue 內容生成。

描述

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

主要語言
C++
星號
120
分支
23
PR 合併指標
30 天內沒有已合併 PR

環境準備

這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

matplotlib/mplcairo 的其他 Issue

查看 matplotlib/mplcairo 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。