Closed
Description
Bug report
Bug summary
When using matplotlib 3.2, the PGF backend and the rcParam "savefig.bbox" set to "tight", plt.savefig
error with ValueError: I/O operation on closed file.
Works fine on 3.1.3.
Code for reproduction
import matplotlib as mpl
mpl.use("pgf")
import matplotlib.pyplot as plt
plt.rcParams.update({"pgf.texsystem": "lualatex", "savefig.bbox": "tight"})
fig, ax = plt.subplots()
ax.plot([1.0, 2.0, 3.0], [4.0, 5.0, 6.0])
plt.savefig("test.pdf")
I don't know if the lualatex is necessary to reproduce, I just didn't have xelatex installed. Without the savefig.bbox it works fine.
Actual outcome
Traceback (most recent call last):
File "test.py", line 9, in <module>
plt.savefig("test.pdf")
File "/usr/local/lib/python3.7/dist-packages/matplotlib/pyplot.py", line 723, in savefig
res = fig.savefig(*args, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/matplotlib/figure.py", line 2203, in savefig
self.canvas.print_figure(fname, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/matplotlib/backend_bases.py", line 2067, in print_figure
self.figure.draw(renderer)
File "/usr/local/lib/python3.7/dist-packages/matplotlib/artist.py", line 38, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/matplotlib/figure.py", line 1734, in draw
self.patch.draw(renderer)
File "/usr/local/lib/python3.7/dist-packages/matplotlib/artist.py", line 38, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/matplotlib/patches.py", line 602, in draw
self._facecolor if self._facecolor[3] else None)
File "/usr/local/lib/python3.7/dist-packages/matplotlib/backends/backend_pgf.py", line 476, in draw_path
writeln(self.fh, r"\begin{pgfscope}")
File "/usr/local/lib/python3.7/dist-packages/matplotlib/backends/backend_pgf.py", line 118, in writeln
fh.write(line)
ValueError: I/O operation on closed file.
Expected outcome
Works in 3.1.3.
Matplotlib version
- Operating system: Debian Stable
- Matplotlib version: 3.2
- Matplotlib backend (
print(matplotlib.get_backend())
): pgf - Python version: 3.7
Installed matplotlib from pip.