Skip to content

Commit 566a7af

Browse files
committed
Fix saving PNGs to file objects in some places.
1 parent 71bdf5a commit 566a7af

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

lib/matplotlib/image.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ def write_png(self, fname):
666666
from matplotlib import _png
667667
im = self.to_rgba(self._A[::-1] if self.origin == 'lower' else self._A,
668668
bytes=True, norm=True)
669-
with open(fname, "wb") as file:
669+
with cbook.open_file_cm(fname, "wb") as file:
670670
_png.write_png(im, file)
671671

672672
def set_data(self, A):

lib/matplotlib/mathtext.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3433,7 +3433,7 @@ def to_png(self, filename, texstr, color='black', dpi=120, fontsize=14):
34333433
from matplotlib import _png
34343434
rgba, depth = self.to_rgba(
34353435
texstr, color=color, dpi=dpi, fontsize=fontsize)
3436-
with open(filename, "wb") as file:
3436+
with cbook.open_file_cm(filename, "wb") as file:
34373437
_png.write_png(rgba, file)
34383438
return depth
34393439

0 commit comments

Comments
 (0)