Closed
Description
Bug report
Bug summary
Saving to svgz fails when bbox_inches="tight"
is being used.
Code for reproduction
import matplotlib.pyplot as plt
plt.step([0, 1], [0, 1])
plt.savefig("myplot.svgz", bbox_inches='tight')
Actual outcome
The svgz file is not created. Instead, the following error is produced:
Traceback (most recent call last):
File "demo.py", line 3, in <module>
plt.savefig("myplot.svgz", bbox_inches='tight')
File "/usr/lib/python3.8/site-packages/matplotlib/pyplot.py", line 723, in savefig
res = fig.savefig(*args, **kwargs)
File "/usr/lib/python3.8/site-packages/matplotlib/figure.py", line 2203, in savefig
self.canvas.print_figure(fname, **kwargs)
File "/usr/lib/python3.8/site-packages/matplotlib/backends/backend_qt5agg.py", line 94, in print_figure
super().print_figure(*args, **kwargs)
File "/usr/lib/python3.8/site-packages/matplotlib/backend_bases.py", line 2079, in print_figure
self.figure.draw(renderer)
File "/usr/lib/python3.8/site-packages/matplotlib/artist.py", line 38, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "/usr/lib/python3.8/site-packages/matplotlib/figure.py", line 1724, in draw
renderer.open_group('figure', gid=self.get_gid())
File "/usr/lib/python3.8/site-packages/matplotlib/backends/backend_svg.py", line 508, in open_group
self.writer.start('g', id="%s_%d" % (s, self._groupd[s]))
File "/usr/lib/python3.8/site-packages/matplotlib/backends/backend_svg.py", line 152, in start
self.__write(self.__indentation[:len(self.__tags) - 1])
ValueError: I/O operation on closed file.
Expected outcome
The svgz plot should be created. All other available formats (eps, pdf, pgf, png, ps, raw, rgba, svg) work properly.
Matplotlib version
The problem occurs on the following system:
- Operating system: Arch Linux (x86_64 Linux 5.5.13-arch1-1)
- Matplotlib version: 3.2.1
- Matplotlib backend (
print(matplotlib.get_backend())
): Qt5Agg - Python version: 3.8.2
It also occurs on these systems:
- Operating system: Fedora
- Environment: conda with conda-forge
- Matplotlib version: 3.2.1 from conda-forge
- Matplotlib backend (
print(matplotlib.get_backend())
): Qt5Agg - Python version: 3.8.2 and 3.7.6
However, it does not occur on these systems:
- Operating system: Fedora
- Environment: conda with conda-forge
- Matplotlib version: 3.0.3 and 3.1.3 from conda-forge
- Matplotlib backend (
print(matplotlib.get_backend())
): Qt5Agg - Python version: 3.7.6
In conclusion, this seems to be a regression from matplotlib 3.1 to matplotlib 3.2