
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.
Size of scatter plot matplotlib how to#

Print "Default size in Inches", DefaultSize # Now check everything with the defaults: e("WXAgg") # do this before pylab so you don'tget the default back end. Print "using MPL version:", matplotlib._version_

This is a small demo file that helps teach how to adjust figure sizes It creates test.png files of different sizes of the same image: #!/usr/bin/env python Here's a test script from the above page. The first link in Google for 'matplotlib figure size' is AdjustingImageSize ( Google cache of the page).
