-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
bbox images do not get placed properly when figure is saved to png or pdf #3918
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
Comments
See the discussion in #2831. I think the issue is that you are specifying the bounding box locations in display units. The transformation from data -> display takes into account things like the final dpi (which is one of the main reasons that the transform system exists). In particular #2831 (comment) has a work-around that should solve your problem short of a complete overhaul of how the rendering backends work. |
@tacaswell Thanks for the suggestion. The figure dpi and the savefig dpi were different and that fixed the png issue. (I have never understood why the figure dpi and savefig dpi do not default to the same values.) I tried to incorporate leejjoon's #2831 (comment) to fix the pdf problem, but I am not sure how to do it without an annotation. Doesn't the The problem I am seeing might be the same as #2831, but I believe there is something different here. Check out the following example,
The pdf with only one image looks correct: |
@tacaswell can I ask you to take a look at my post above? I think my issue is not quite a duplicate of issue #2831. When I use |
I modified your example a little bit. I flipped the second image: |
@WeatherGod, thanks for confirming the bug. It appears that, no matter where I place the two images, they both get moved to the lower left corner of the axes when the figure is saved as a pdf. For example, here is the matplotlib figure window: |
Oh, now that's interesting! It is as if none of the transform data is being
|
attn @jenshnielsen |
After an evening of digging, I believe I found the issue. In the
When the The
then my two images also do not get moved when I save as a pdf. So now, the question is, what should I do to fix this? I tried adding code to the pdf backend to make |
@mdboom, I noticed that you put originally put in |
My guess would be that this is for efficiency. The reason that the mixed-mode rendering exists (as I understand it) is so that you don't try to write a 1kx1k image into a 1inx1in region (that will eventually be rendered at 100dpi on the screen) as 10e6 square patches. By the same token, you don't want to render two large bit maps to be inserted into the vector document which will ultimately overlap. This works correctly if you use Another possible reason is that at least the ps backend does not deal with alpha correctly so if you have multiple images with alpha which overlap you need to composite them in AGG. Why do you want to move the images around later? What use-case is that covering that can't be covered by mpl? |
Thanks for the reply, tacaswell. The reasons you list for mixed-mode rendering make sense. I like to move the images around later, because I frequently will save a sequence of, say 5, vertically stacked images, and then I will realize 3 months later that I want to horizontally stack them, stagger them, overlap them, or something else. Usually I am in a hurry to put together a presentation or a writeup for something. Rather than dig up the old code, and rewrite it to do staggered images, I would much rather just work in Adobe Illustrator to manipulate the images on the fly. I find the GUI is the way to go for quick, single time, operations. If find myself doing the same GUI operations over and over again, then I will go to the effort to code it up. What about if I left
|
Fair enough. This is just one more use-case where having proper serialization for figures (so you can just load the figure back up (data and all?!?) poke at the objects and re-save). I am not super familiar with the mixed mode code (I read it a year ago, but it has exited the FIFO buffer of my memory), wouldn't the rcparam option still run afoul of the mixed mode assert? Why doesn't the SVG code run afoul of it? The smash-down-to-one-image approach also leads to some really annoying z-order issues (if you have overlapping image, line, image in that order, pdf renders them as image, image, line) so it probably should be made configurable how the mixed-mode rendering deals with compositing (and make it smart enough to only smash down artists that are adjacent in the layer). That also side step this bug, fix an annoying long-standing bug, and solve your use-case. |
The SVG backend does not run into trouble with the mixed mode assert because it does not use the According to the
I am thrilled it converts things like quad meshes to raster images, because Matlab did not, which was a pain in the rear. As far as I can tell, the smashing-images-down-to-one actually seems to happen inside axes/._base right after the To answer your question, yes, the rcParam option would still run afoul of the mixed mode assert. I would have to delete the assert, but I think that Also, if |
Well, I spent the evening trying to figure out why the |
Don't feel discouraged! I have lost track of how many evenings I have spent failing to understand various bits of the code base. If you think you can clean anything you have been reading up a bit, please have at it (just make sure the test coverage is pretty good before you start). I suspect that everywhere the code is assuming that someplace else will deal with the transform on the artist which means this probably going to be a very subtle bug which will require adding one or two lines to fix 😈 . |
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help! |
This now works, however I have not bisected back to when it was fixed. |
@tacaswell how do you know this issue is resolved? When I try to run the code in my Dec 13, 2014 post, I get the following error: |
I ran this with 3.6 when that was just a warning. Change |
Thanks, tacaswell. Running the code in my Dec 13, 2014 post, except with |
When I create a figure using bbox images, everything looks fine, but when I save the figure, the images move. Here is an example
If I take a screenshot of the figure window, it looks like this



which is what I expect. However, when I look at the 'png_test.png', the second image that did not use the
TransformedBbox
moves, as shown belowIn the pdf, both images move, as shown below
In case it matters, I am using the Qt4Agg interactive backend with the Spyder IDE. My matplotlib version is 1.4.0.
The text was updated successfully, but these errors were encountered: