Skip to content

PGF backend + savefig.bbox results in I/O error in 3.2 #16731

@Psirus

Description

@Psirus

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.

Metadata

Metadata

Assignees

Labels

Release criticalFor bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.backend: pgf

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    pFad - Phonifier reborn

    Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

    Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy