Skip to content
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

Fixes for File Saving in Webagg #3981

Merged
merged 3 commits into from
Jan 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 1 addition & 2 deletions lib/matplotlib/backends/backend_webagg.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import datetime
import errno
import io
import json
import os
import random
Expand Down Expand Up @@ -197,7 +196,7 @@ def get(self, fignum, fmt):

self.set_header('Content-Type', mimetypes.get(fmt, 'binary'))

buff = io.BytesIO()
buff = six.BytesIO()
manager.canvas.print_figure(buff, format=fmt)
self.write(buff.getvalue())

Expand Down
3 changes: 2 additions & 1 deletion lib/matplotlib/backends/backend_webagg_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,8 @@ def get_javascript(cls, stream=None):
for filetype, ext in sorted(FigureCanvasWebAggCore.
get_supported_filetypes_grouped().
items()):
extensions.append(ext[0])
if not ext[0] == 'pgf': # pgf does not support BytesIO
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the record @pwuertz.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At some point I added support for writing to targets that are matplotlib.cbook.is_writable_file_like. Yet writing pgf instead of pdf or png to a stream raises a UserWarning since there is no way of embedding rastered images within PGF.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or are you saying that the backend currently doesn't work with BytesIO instances at all? If so, we should open a new issue and I will look into that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If possible, I think it's preferable to fix this at the source (having pgf support BytesIO objects, if that's possible), rather than papering around it here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think this should be back ported

On Thu, Jan 8, 2015, 07:28 Michael Droettboom notifications@github.com
wrote:

In lib/matplotlib/backends/backend_webagg_core.py
#3981 (diff)
:

@@ -403,7 +403,8 @@ def get_javascript(cls, stream=None):
for filetype, ext in sorted(FigureCanvasWebAggCore.
get_supported_filetypes_grouped().
items()):

  •        extensions.append(ext[0])
    
  •        if not ext[0] == 'pgf':  # pgf does not support BytesIO
    

If possible, I think it's preferable to fix this at the source (having pgf
support BytesIO objects, if that's possible), rather than papering around
it here.


Reply to this email directly or view it on GitHub
https://github.com/matplotlib/matplotlib/pull/3981/files#r22648899.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Backporting is fine, but what I was getting at is that it's probably a bug that pgf doesn't support BytesIO, and we should fix that rather than just not allowing it in the NbAgg interface. Though this is fine for now, we'll probably want to undo it later.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That comment went someplace very surprising...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created a new issue #3982 to track the underlying problem.

extensions.append(ext[0])
output.write("mpl.extensions = {0};\n\n".format(
json.dumps(extensions)))

Expand Down