Closed
Description
Bug report
Bug summary
When the PGF backend is selected, saving figures to a PNG image does not work because invoking pdftocairo
fails with exit code 99. Saving to a PDF file and then invoking pdftocairo
with the same arguments works.
Code for reproduction
# plot_to_png.py
import matplotlib as mpl
mpl.use("pgf")
from matplotlib import pyplot as plt
plt.plot([1, 2, 3], [4, 5, 6])
plt.savefig("test.png")
Executing this leads to
me@home:/tmp/mpl » python plot_to_png.py
Traceback (most recent call last):
File "plot_to_png.py", line 6, in <module>
plt.savefig("test.png")
File "/usr/lib/python3.6/site-packages/matplotlib/pyplot.py", line 697, in savefig
res = fig.savefig(*args, **kwargs)
File "/usr/lib/python3.6/site-packages/matplotlib/figure.py", line 1572, in savefig
self.canvas.print_figure(*args, **kwargs)
File "/usr/lib/python3.6/site-packages/matplotlib/backend_bases.py", line 2244, in print_figure
**kwargs)
File "/usr/lib/python3.6/site-packages/matplotlib/backends/backend_pgf.py", line 961, in print_png
self._print_png_to_fh(fh, *args, **kwargs)
File "/usr/lib/python3.6/site-packages/matplotlib/backends/backend_pgf.py", line 941, in _print_png_to_fh
converter(fname_pdf, fname_png, dpi=self.figure.dpi)
File "/usr/lib/python3.6/site-packages/matplotlib/backends/backend_pgf.py", line 197, in cairo_convert
check_output(cmd, shell=True, stderr=subprocess.STDOUT)
File "/usr/lib/python3.6/subprocess.py", line 336, in check_output
**kwargs).stdout
File "/usr/lib/python3.6/subprocess.py", line 418, in run
output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['pdftocairo', '-singlefile', '-png', '-r 100', '/tmp/mpl_pgf_klhh_fnt/figure.pdf', '/tmp/mpl_pgf_klhh_fnt/figure']' returned non-zero exit status 99.
me@home:/tmp/mpl »
Expected outcome
This should produce a PNG file of a linear graph.
Saving to a PDF file and then calling pdftocairo
works:
# plot_to_pdf.py
import matplotlib as mpl
mpl.use("pgf")
from matplotlib import pyplot as plt
plt.plot([1, 2, 3], [4, 5, 6])
plt.savefig("test.pdf")
me@home:/tmp/mpl » python plot_to_pdf.py
me@home:/tmp/mpl » pdftocairo -singlefile -png -r 100 /tmp/mpl/test.pdf /tmp/mpl/test
me@home:/tmp/mpl » echo $?
0
me@home:/tmp/mpl »
Used program versions
- Arch Linux
-
from the Arch repo
Python 3.6.0 (default, Jan 16 2017, 12:12:55) [GCC 6.3.1 20170109] on linux
- Matplotlib version 2.0.0, also installed from Arch repo
- pdftocairo version 0.52.0, also from Arch repo (package is named
poppler
)
Prior to updating to Matplotlib 2.0.0 (from 1.5.3) and pdftocairo 0.52.0 (from 0.51.0), this worked.