-
Notifications
You must be signed in to change notification settings - Fork 25
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
Resulting media size differs from declared one #129
Comments
Thank you for the notification and for giving clear examples. I took the liberty to create an issue from your comment, so we can discuss a solution. I agree with you @daskol that setting a figure size to a value and having the saved figure be differently sized is unexpected. However, the discrepancy between what we pass to "figsize" and the size of the saved image seems to be a decision made in matplotlib, not Tueplots. Since the exact size of the saved figure is also affected by other variables, e.g., constrained/tight layouts (see here), I am not sure whether we can expect an exact match in either case. But I think the reduced figure size should at least be documented. A natural place would be the FAQ part of Tueplots' documentation. We can also think about exposing the savefig.bbox variable as a function argument (just like savefig.pad_inches) to have more control over this behaviour. What do you think @daskol? Would this work for you? |
Thank you for replying to my comment and creating the issue. In my opinion, the best solution we can do is not to set bbox by default and leave the decision to tighten bbox or not to user. There are multiple reasons for that. First of all, the principle of the least surprise is fulfilled: size of media will be what user expects. Another reason is related to how layout engine in Matplotlib works. As far as I understand, Concerning the overfull hbox issue, I'd prefer to let a user know about the difficulties in layouting of a figure. In my experience, it is quite often the situation that hbox is overfilled because of Personally, I just override these options for saving as follows. with mpl.rc_context({'savefig.bbox': 'standard'}):
fig.savefig('raster.png')
fig.savefig('vector.svg') |
Thanks for clarifying! So you suggest removing the I think this makes sense. Adding to your reasons, I (now) think that changing the Would you be willing to send a PR that deletes those few lines from
I do not quite understand what you explain here. Do you refer to the |
Then we get images with different size in pixels while DPI is the same and equals to 100.
$ file *.png standard.png: PNG image data, 325 x 200, 8-bit/color RGBA, non-interlaced tight.png: PNG image data, 319 x 195, 8-bit/color RGBA, non-interlaced
Bounding boxes of generated PDFs differs too.
From my perspective
matplotlib
documentation is a little bit vague and unclear at this point but it seems thatsavefig.bbox
/bbox_inches
tweak somehow shape of bounding box ofArtist
's onFigure
and use it instead of bounding box of original canvas.UPD I don't know what figsize and dpi was in your sample abut sizes of generated PDFs follow.
Originally posted by @daskol in #101 (comment)
The text was updated successfully, but these errors were encountered: