Description
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
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:
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