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
savefig to sys.stdout fails with pdf backend #1089
Comments
This doesn't occur on master. Will be fixed by 1.2 (release candidate will be available soonish). |
@pelson Hallo and thanks for replying. Did you check it against a older version of the code as well to see if you could reproduce it. Because if it is a file permission problem, then perhaps that wouldn't be replicated in a local copy of the code. |
No I didn't. I will boot my virtual machine to give it a shot. (I can't build on mountain lion before a recent change to master). |
No I haven't seen it in master. I'm haven't contributed to matplotlib yet, so I don't have it set up to run from git yet. I only asked because of the suspicion that it might be a file permission error, and that may not even be correct. If your tests indicate that it works fine on osx (right), maybe I'll see if I can figure out how to set it up myself and check it on linux. |
I'm glad you asked. I should have tried reproducing the problem first, and then seeing that it had actually been resolved. I can confirm this issue on Ubuntu 12.04 master (just before 1.2.x), but I do not get the problem on OSX 10.8. Presumably to do with some differences in sys.stdout between the two operating systems... @KennethNielsen: Thanks for the nudge. |
Evidently the tell() method is supported on sys.stdout on OSX but not on linux. I would not have expected it to be supported on any operating system. It is called 4 places in backend_pdf.py, apparently for two different purposes. Removing it looks non-trivial. |
On my Fedora box it has a tell:
It should be noted that we don't explicitly support using EDIT: Of course, having a tell isn't enough. It fails with an |
Your answer is reasonable, though; I don't see any urgency in making the pdf backend support streams. |
I've put it on the wishlist. I haven't tagged it with "low hanging fruit" based on @efiring's comments. I believe the workaround is to write to a stringio and then pipe the output to stdout. @KennethNielsen: If you do this, please feel free to share the code. |
@efiring Thanks for troubleshooting
works just fine (the other values of self.o['image_format'] are eps, png and svg). As for making a change in mpl I guess a similar approach might fix it, but it will probably double the memory usage for the file. I'll look into it if I find the time. |
The resulting pdf is actually broken on MacOS too - though probably most viewers can fix it. The offsets in the xref table depend on the results of tell(), which includes everything printed before the pdf file (try calling savefig(sys.stdout, format='png') several times - the table of zero-padded numbers keeps changing every time). |
I presume the pull request fixed this? |
Yes, as far as my testing of your branch is enough to confirm, then yes, it is fixed. I unfortunately don't have the option to test matplotlib master in the "produktion" environment (where the original problem was) and will therefore have to wait until a packaged version containing the fix trickles down to CentOS (so probably in half a decade or so G). Thanks again for your work. |
Matplotlib 0.99.1.1 and 1.1.1rc crahes when I try to save image data to sys.stdout with the pdf backend (but works with the png backend). The error can be reproduced with this code by commenting out the savefig png line and commenting in the savefig pdf line.
It produces some of the header and then fails with this traceback:
My first thought (well technically a colleague of mine) was that it was some sort of a permission problem with the mpl files, i.e. that the one the pdf backend lives in doesn't have permission to write to sys.stdout. We checked if this was a packaging problem, so we tested it both on a ubuntu and centos system, with the same result.
If you need any more information, please let me know.
The text was updated successfully, but these errors were encountered: