Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Bug]: Matplotlib PGF backend uses the wrong font... But only in a beamer presentation! #25923

Copy link
Copy link
Open
@massimiliano-leoni

Description

@massimiliano-leoni
Issue body actions

Bug summary

I noticed that, when adding PGF pictures to a beamer document, not all the fonts in the picture are correct.
For example, in the slide
wrongFont
you can see that the slide title is using a certain font while the plot labels and legend are using a different font. Curiously, the units of measure, created with the siunitx package, do use the same font as the slide title, which is correct.

I inspected the generated pgf file and I noticed that all the labels are prefixed with \rmfamily. If I remove that command, then I get the correct output:
rightFont

Also worth noting is that when I compile a regular document, with \documentclass{article} for example, I always get the right fonts for all labels in the plot, with or without \rmfamily.

I am not 100% sure why the \rmfamily instruction is there, but removing it fixed the output in beamer. Maybe it can be omitted? 🤔

Or maybe there's a valid LaTeX explanation for this?

Code for reproduction

# this code snippet is only a sketch of the actual one

import matplotlib
matplotlib.use("pgf")

import matplotlib.pyplot as plt

params = {
    'text.usetex'       : True,
    "pgf.texsystem": "pdflatex",
    'font.family': 'serif',
    'pgf.rcfonts': False,
    "pgf.preamble": r"\usepackage{siunitx}"
}

matplotlib.rcParams.update(params)

# omitted stuff...

plt.plot(x, d, "*", label="data")
plt.plot(x, y, label="linear regression")
plt.xlabel(r"input (\si{L/min})")
plt.ylabel(r"output  (\si{L/min})")
plt.legend()
plt.savefig("linearRegression.pgf")

Actual outcome

See the first figure in the description

Expected outcome

See the second figure in the description

Additional information

No response

Operating system

Linux KDE Neon

Matplotlib Version

3.7.1

Matplotlib Backend

No response

Python version

3.10.6

Jupyter version

No response

Installation

pip

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.