I managed to work around those with Removing white space around a saved image plt.tight_layout(pad=1) So it does seem that fonts are scaling correctly, we just get some trouble for very small widths with labels getting cut off, e.g. If you really need a specific width in addition to height, this seems to work OK: width.py #!/usr/bin/env python3 Plt.savefig(dpi=h/fig.get_size_inches() + width control this is an important use case that I don't have a great solution for yet.Īsked at: How to obtain a fixed height in pixels, fixed data x/y aspect ratio and automatically remove remove horizontal whitespace margin in Matplotlib? Which gives the exact desired height for height equals 431:įixed height, set_aspect, automatically sized width and small marginsĮrmmm, set_aspect messes things up again and prevents plt.tight_layout from actually removing the margins. Instead, this other approach proposed in the same question seems to work well: plt.tight_layout(pad=1) However, that works by cropping the image, and you won't get the desired sizes with it. Removing white space around a saved image I always feel that there is too much white space around images, and tended to add bbox_inches='tight' from: Plt.savefig(bbox_inches='tight' changes image size I tend to set just the height because I'm usually most concerned about how much vertical space the image is going to take up in the middle of my text. I think this is what I'll go with most of the time, as it is simple and scales: get_size.py #!/usr/bin/env python3 My best approach so far: plt.savefig(dpi=h/fig.get_size_inches() height-only control Just to have a comparison point: base.py #!/usr/bin/env python3 I couldn't easily find an upstream discussion about this.īaseline example without trying to set the image dimensions Summary of current status: things are messy, and I am not sure if it is a fundamental limitation, or if the use case just didn't get enough attention from developers. Here is a quick comparison of some of the approaches I've tried with images showing what the give.
0 Comments
Leave a Reply. |