8000 backend_pgf: Partial support of file-like streams without filenames (… · htylab/matplotlib@d8965dd · GitHub
[go: up one dir, main page]

Skip to content

Commit d8965dd

Browse files
committed
backend_pgf: Partial support of file-like streams without filenames (fixes matplotlib#3982)
1 parent d014a8d commit d8965dd

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

lib/matplotlib/backends/backend_pgf.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,10 @@ def __init__(self, figure, fh, dummy=False):
431431
self.__dict__[m] = nop
432432
else:
433433
# if fh does not belong to a filename, deactivate draw_image
434-
if not os.path.exists(fh.name):
434+
if not hasattr(fh, 'name') or not os.path.exists(fh.name):
435+
warnings.warn("streamed pgf-code does not support raster "
436+
"graphics, consider using the pgf-to-pdf option",
437+
UserWarning)
435438
self.__dict__["draw_image"] = lambda *args, **kwargs: None
436439

437440
def draw_markers(self, gc, marker_path, marker_trans, path, trans, rgbFace=None):
@@ -835,11 +838,8 @@ def print_pgf(self, fname_or_fh, *args, **kwargs):
835838
with codecs.open(fname_or_fh, "w", encoding="utf-8") as fh:
836839
self._print_pgf_to_fh(fh, *args, **kwargs)
837840
elif is_writable_file_like(fname_or_fh):
838-
if not os.path.exists(fname_or_fh.name):
839-
warnings.warn("streamed pgf-code does not support raster "
840-
"graphics, consider using the pgf-to-pdf option",
841-
UserWarning)
842-
self._print_pgf_to_fh(fname_or_fh, *args, **kwargs)
841+
fh = codecs.getwriter("utf-8")(fname_or_fh)
842+
self._print_pgf_to_fh(fh, *args, **kwargs)
843843
else:
844844
raise ValueError("filename must be a path")
845845

0 commit comments

Comments
 (0)
0