I've boiled down a problem and while the following my look useless, I need to understand why matplotlib is behaving like it is.
Below is code showing my issue. I don't believe the issue is with the "bbox_inches='tight'", if you leave that off, my image is indeed, 800x1400, but the last row is a row of transparent pixels(on linux/not mac). It's difficult to see unless you use the imagemagik command display.
The basic problem is that when my data has an aspect ratio very close to 1.75, the image gets changed to one with an aspect of 1.74875.
Correct figure info 8x14@...4246... = 800x1400 => 1.75 Aspect Ratio.
Incorrect figure info => 800x1399 => 1.74875
Data that works aspect ratio: 1.7499999999999998
Data that fails aspect ratio: 1.7499999999999996
---> Srsly?! -------------------------------^
It would be great if someone could explain to me what's happening if this is indeed working as expected. If it's not, it would be great if someone could fix it.
Thanks in advance.
import matplotlib.pyplot as plt
# I want an 800x1400 image (aspect = 1400/800 = 1.75.
fig = plt.figure(1, figsize=(8, 14), frameon=False, dpi=100)
# Use the whole figure and fill with a patch.
fig.add_axes([0, 0, 1, 1])
ax = plt.gca()
limb = ax.axesPatch
# Set some bounds with Aspects very close to the desired aspect ratios.
x1 = 0.0
y1 = 0.0
x2 = 16.
# If you un-comment out this line (and comment the one below). I get an image I expect
# y2 = 27.999999999999994671 # produces 800 x 1400 image
# aspect = 1.7499999999999998 works
# Use this line and I get and image the wrong size (or with transparent pixels.)
y2 = 27.999999999999994670 # produces (wrong?) 800 x 1399 image
# aspect = 1.7499999999999996 Fails? wat?
corners = ((x1, y1), (x2, y2))
plt.savefig('rectangle.png', pad_inches=0.0, bbox_inches='tight')
# If you use this below, the file size is correct, but there is a single
# line transparent pixels along the bottom of the image
# plt.savefig('rectangle.png', pad_inches=0.0)
if __name__ == '__main__':