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

Conversation

blink1073
Copy link
Member

Closes #3979. Uses six.BytesIO for compatibility, which prevents a bug when using PIL (not Pillow) related to io.BytesIO. Also, the pgf backend relies on writing encoded text to a file, which is incompatible with BytesIO.

@@ -197,7 +197,13 @@ def get(self, fignum, fmt):

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

buff = io.BytesIO()
# override fileno to raise AttributeError so PIL doesn't error
class BytesIO(io.BytesIO):
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be laundered through six? https://pythonhosted.org/six/#six.BytesIO

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, that might actually solve both problems...

Copy link
Member Author

Choose a reason for hiding this comment

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

No, pgf would still require some gymnastics (I don't think its worth it).

@blink1073
Copy link
Member Author

Tested with Python 3.4 and 2.7.

@@ -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.

pelson added a commit that referenced this pull request Jan 8, 2015
@pelson pelson merged commit d014a8d into matplotlib:master Jan 8, 2015
@pelson
Copy link
Member

pelson commented Jan 8, 2015

Awesome, thanks @blink1073.

@pelson
Copy link
Member

pelson commented Jan 8, 2015

@tacaswell - I think we should backport this. Do you agree?

pelson added a commit that referenced this pull request Jan 8, 2015
@tacaswell
Copy link
Member

backported as 4c12d81

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WebAgg Saving JPEG Raises Error
5 participants