Thanks to visit codestin.com
Credit goes to github.com

Skip to content

pgf can not write to BytesIO [back port to 1.4.x] #3982

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 9, 2015
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
backend_pgf: Partial support of file-like streams without filenames (f…
…ixes #3982)
  • Loading branch information
pwuertz committed Jan 9, 2015
commit d8965dd84d039f4cff5578ade372f94806cb7578
12 changes: 6 additions & 6 deletions lib/matplotlib/backends/backend_pgf.py
Original file line number Diff line number Diff line change
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