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

Aberta
#66 2 comentários 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
3/5
Tempo estimado
1-2 dias
Facilidade para iniciantes
72/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
cpp, matplotlib, python
Domínio
backend

Direção de pesquisa

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.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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

Linguagem predominante
C++
Estrelas
120
Forks
23
Métricas de merge de PRs
Nenhum PR com merge em 30d

Preparar o ambiente

Este projeto não oferece contêiner de desenvolvimento, Dockerfile nem guia de contribuição, então a configuração fica por sua conta: comece pelo README e veja nosso guia da primeira contribuição para os passos gerais.

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de matplotlib/mplcairo

Todas as issues de matplotlib/mplcairo

Issues semelhantes

Mais issues de C++

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.