matplotlib / matplotlib

matplotlib: plotting with Python
https://matplotlib.org/stable/
20.39k stars 7.68k forks source link

[Bug]: svg.fonttype = none and text.usetex = True not working together #22971

Open paulgoulain opened 2 years ago

paulgoulain commented 2 years ago

Bug summary

When saving a figure in svg using the option text.usetex = True, the texts in the obtained svg picture are rendered as path.

Code for reproduction

from pathlib import Path
import matplotlib.pyplot as plt

this_dir = Path(__file__).parents[0]

plt.rcParams['svg.fonttype'] = 'none'
plt.rcParams['text.usetex'] = True

x = [0, 10]

fig, ax = plt.subplots()
ax.plot(x, x)
fig.savefig(this_dir/'test.svg')

Actual outcome

image

As an example, the label here is a path svg object.

Expected outcome

image

Here the same plot, with the line plt.rcParams['text.usetex'] = True commented

Additional information

No response

Operating system

Windows

Matplotlib Version

3.5.2

Matplotlib Backend

No response

Python version

3.10

Jupyter version

No response

Installation

pip

oscargus commented 2 years ago

The problem, if I get it correctly, is that the results from latex (which is used to generate the "text") is really read as paths before being inserted in the figure, so there is basically no text information left (except the comment then).

Even though one may think that it could work in this case, you may also imagine the challenge representing a more complicated expression with square roots and integrals as editable text.

paulgoulain commented 2 years ago

How does the latex output is used by matplotlib ? I'm not familiar with the process. Because if the problem is to retrieve information from the latex output (DVI or PDF) to feed the xml, I found this tool that converts DVI to SVG (https://dvisvgm.de/)