diff --git a/lib/matplotlib/backends/backend_pgf.py b/lib/matplotlib/backends/backend_pgf.py index 915ad597bd6b..c246bf978c1f 100644 --- a/lib/matplotlib/backends/backend_pgf.py +++ b/lib/matplotlib/backends/backend_pgf.py @@ -431,7 +431,10 @@ def __init__(self, figure, fh, dummy=False): self.__dict__[m] = nop else: # if fh does not belong to a filename, deactivate draw_image - if not os.path.exists(fh.name): + if not hasattr(fh, 'name') or not os.path.exists(fh.name): + warnings.warn("streamed pgf-code does not support raster " + "graphics, consider using the pgf-to-pdf option", + UserWarning) self.__dict__["draw_image"] = lambda *args, **kwargs: None 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): with codecs.open(fname_or_fh, "w", encoding="utf-8") as fh: self._print_pgf_to_fh(fh, *args, **kwargs) elif is_writable_file_like(fname_or_fh): - if not os.path.exists(fname_or_fh.name): - warnings.warn("streamed pgf-code does not support raster " - "graphics, consider using the pgf-to-pdf option", - UserWarning) - self._print_pgf_to_fh(fname_or_fh, *args, **kwargs) + fh = codecs.getwriter("utf-8")(fname_or_fh) + self._print_pgf_to_fh(fh, *args, **kwargs) else: raise ValueError("filename must be a path") diff --git a/lib/matplotlib/backends/backend_webagg_core.py b/lib/matplotlib/backends/backend_webagg_core.py index 7a4bec1a325a..8f971600d040 100644 --- a/lib/matplotlib/backends/backend_webagg_core.py +++ b/lib/matplotlib/backends/backend_webagg_core.py @@ -403,8 +403,7 @@ def get_javascript(cls, stream=None): for filetype, ext in sorted(FigureCanvasWebAggCore. get_supported_filetypes_grouped(). items()): - if not ext[0] == 'pgf': # pgf does not support BytesIO - extensions.append(ext[0]) + extensions.append(ext[0]) output.write("mpl.extensions = {0};\n\n".format( json.dumps(extensions)))