Skip to content

Commit

Permalink
Merge pull request #3982 from pwuertz/fix_3982
Browse files Browse the repository at this point in the history
pgf can not write to `BytesIO` [back port to 1.4.x]
  • Loading branch information
pelson committed Jan 9, 2015
2 parents 580d990 + 9fcd026 commit 174b126
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
12 changes: 6 additions & 6 deletions lib/matplotlib/backends/backend_pgf.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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")

Expand Down
3 changes: 1 addition & 2 deletions lib/matplotlib/backends/backend_webagg_core.py
Expand Up @@ -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)))

Expand Down

0 comments on commit 174b126

Please sign in to comment.