Skip to content

[Bug]: Saving as an SVG and PDF produce different outputs with Latex characters, with wrong character sizing #29791

Closed
@jamesmeiklejohn

Description

@jamesmeiklejohn

Bug summary

When saving certain outputs using Latex rendering as an SVG, it produces wrong outputs. Using plt.show() it renders correctly, and it works for saving as a PDF, but saving the output as a SVG math environment characters can render in the wrong size (see attached screenshots.)

Code for reproduction

from pathlib import Path
import pandas as pd
import matplotlib.pyplot as plt
import scienceplots


BASE_PATH = Path(__file__).parent
DATA_PATH = BASE_PATH / "ion_ranges.csv"


plt.style.use(['science', 'latex-siunitx'])

dat = pd.read_csv(DATA_PATH)

plt.plot(dat["energy"], dat["projected_range_um"], marker="o", linestyle="-")
plt.xlabel("Energy (keV)")
plt.ylabel(r"Projected Range (\si{\um})")
plt.tight_layout()
plt.savefig(BASE_PATH / "ion_ranges_plot.pdf")

Actual outcome

Image

Expected outcome

ion_ranges_plot.pdf

Additional information

No response

Operating system

No response

Matplotlib Version

3.10.1

Matplotlib Backend

No response

Python version

No response

Jupyter version

No response

Installation

None

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions