X Tutup
The Wayback Machine - https://web.archive.org/web/20201006132523/https://github.com/matplotlib/matplotlib/issues/18614
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

Returning bytes data from savefig #18614

Open
anntzer opened this issue Sep 30, 2020 · 9 comments
Open

Returning bytes data from savefig #18614

anntzer opened this issue Sep 30, 2020 · 9 comments

Comments

@anntzer
Copy link
Contributor

@anntzer anntzer commented Sep 30, 2020

Problem

#6909 is a PR, abandoned by the original author, that made bytestring = fig.savefig(None, **kwargs) equivalent to import io; buf = io.BytesIO(); fig.savefig(buf, **kwargs); bytestring = buf.getvalue() which is in itself a handy simplification. I think there was general agreement about the feature, it just needs some tests (which should be made simpler than in the original PR -- that was one of the remaining sticky points, I think).

Proposed Solution

Revive #6909.

Additional context and prior art

@hs2361
Copy link

@hs2361 hs2361 commented Oct 2, 2020

The current way of saving the figure as a byte string is by using None as the file name, correct? The original PR wanted to add a new method (to_bytes or write_bytes) to the fig object to make this conversion more explicit? I'm new to the community, so I would be grateful if you could give me some more guidance.

@jklymak
Copy link
Contributor

@jklymak jklymak commented Oct 2, 2020

No thats backwards. None was the proposed way to do that. The current way is to make a BytesIO buffer and write to that instead of a disk buffer..

@hs2361
Copy link

@hs2361 hs2361 commented Oct 2, 2020

No thats backwards. None was the proposed way to do that. The current way is to make a BytesIO buffer and write to that instead of a disk buffer..

Ok, so instead of making a new method on the fig object, you're proposing that whenever None is entered as the file name, it savefig should return a bytes string. Is that correct?

@jklymak
Copy link
Contributor

@jklymak jklymak commented Oct 2, 2020

Thats my understanding, but of course you should check the PR details.

@hs2361
Copy link

@hs2361 hs2361 commented Oct 4, 2020

@tacaswell is of the opinion that we shouldn't change the return type of the savefig method simply based on an input type or a kwarg (refer to this comment). He suggested that we could add it as a separate function rather than adding another method to Figure.

@jklymak
Copy link
Contributor

@jklymak jklymak commented Oct 4, 2020

... keep reading 😉

@hs2361
Copy link

@hs2361 hs2361 commented Oct 5, 2020

Oh alright, @tacaswell in this comment (#6909 (comment)) said that he thinks using None as the file name should return a bytestring. I will try to re-implement what was done in the PR then, if that's alright?

@jklymak
Copy link
Contributor

@jklymak jklymak commented Oct 5, 2020

@hs2361 I think that would be fine. I don't personally need this feature, but sounds like @anntzer thinks it would be useful?

@hs2361
Copy link

@hs2361 hs2361 commented Oct 5, 2020

@hs2361 I think that would be fine. I don't personally need this feature, but sounds like @anntzer thinks it would be useful?

@anntzer also mentioned simplifying the tests. @efiring mentioned in the comments for the PR that the tests were unnecessarily complex for the code being added in.

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

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.
X Tutup