pgf backend in matplotlib – "input stack size" capacity exceeded with pdflatex and lualatex
Question:
I’m trying to use the pgf backend in matplotlib to create figure files for a manuscript, following the example in the matplotlib docs here. I don’t have xelatex so I’ve tried using pdflatex and lualatex. However, if I try to use the docs’ example and save the figure, I get an error. Internet searching hasn’t helped much. I would be grateful to know if I am doing something wrong, or if it works for other people (in which case knowing your matplotlib and pdfTeX/LuaTeX versions would be helpful – mine are matplotlib 3.5.1, pdfTeX 3.1415926-2.5-1.40.14 (TeX Live 2013) and LuaTeX beta-0.76.0-2020040104). Or is it likely that something in my TeX setup needs to be changed?
The error message I get is
! LaTeX Error: File `pdftex.def' not found.
Type X to quit or <RETURN> to proceed,
or enter new name. (Default extension: def)
Enter file name: ! TeX capacity exceeded, sorry [input stack size=5000].
<argument> usepackage
[T1]{fontenc}
l.92 ...ed{ver@Gin@driver}{input{Gin@driver}}{}
This is with the following code, using the example in the docs:
import matplotlib.pyplot as plt
plt.rcParams.update({
"pgf.texsystem": "pdflatex",
"pgf.preamble": "n".join([
r"usepackage[utf8x]{inputenc}",
r"usepackage[T1]{fontenc}",
r"usepackage{cmbright}",
]),
})
fig, ax = plt.subplots(figsize=(4.5, 2.5))
ax.plot(range(5))
ax.text(0.5, 3., "serif", family="serif")
ax.text(0.5, 2., "monospace", family="monospace")
ax.text(2.5, 2., "sans-serif", family="sans-serif")
ax.set_xlabel(r"ยต is not $mu$")
fig.tight_layout(pad=.5)
fig.savefig('/user/home/test.pdf', backend='pgf')
The last line is how I’m trying to save the file, which is the only line not in the docs’ example, but it says above that this should work. The other methods it gives to use the backend don’t work either.
Answers:
Upgrading to TexLive 2022 solved this issue.
I’m trying to use the pgf backend in matplotlib to create figure files for a manuscript, following the example in the matplotlib docs here. I don’t have xelatex so I’ve tried using pdflatex and lualatex. However, if I try to use the docs’ example and save the figure, I get an error. Internet searching hasn’t helped much. I would be grateful to know if I am doing something wrong, or if it works for other people (in which case knowing your matplotlib and pdfTeX/LuaTeX versions would be helpful – mine are matplotlib 3.5.1, pdfTeX 3.1415926-2.5-1.40.14 (TeX Live 2013) and LuaTeX beta-0.76.0-2020040104). Or is it likely that something in my TeX setup needs to be changed?
The error message I get is
! LaTeX Error: File `pdftex.def' not found.
Type X to quit or <RETURN> to proceed,
or enter new name. (Default extension: def)
Enter file name: ! TeX capacity exceeded, sorry [input stack size=5000].
<argument> usepackage
[T1]{fontenc}
l.92 ...ed{ver@Gin@driver}{input{Gin@driver}}{}
This is with the following code, using the example in the docs:
import matplotlib.pyplot as plt
plt.rcParams.update({
"pgf.texsystem": "pdflatex",
"pgf.preamble": "n".join([
r"usepackage[utf8x]{inputenc}",
r"usepackage[T1]{fontenc}",
r"usepackage{cmbright}",
]),
})
fig, ax = plt.subplots(figsize=(4.5, 2.5))
ax.plot(range(5))
ax.text(0.5, 3., "serif", family="serif")
ax.text(0.5, 2., "monospace", family="monospace")
ax.text(2.5, 2., "sans-serif", family="sans-serif")
ax.set_xlabel(r"ยต is not $mu$")
fig.tight_layout(pad=.5)
fig.savefig('/user/home/test.pdf', backend='pgf')
The last line is how I’m trying to save the file, which is the only line not in the docs’ example, but it says above that this should work. The other methods it gives to use the backend don’t work either.
Upgrading to TexLive 2022 solved this issue.