Inspired by this question, I've been trying to get images plotted without gaps.
In my toy example I have four images that I want to place in two rows. They have different shapes: different number of rows, same number of columns. Despite the differences, they should fit in a single figure without gaps, as in the following illustration:
When I try to get them together, though, setting plt.subplots_adjust(wspace=0, hspace=0) doesn't do the trick, because the images have different shapes.
Here's the code:
from numpy.random import rand
import matplotlib.pyplot as plt
test_data = [[rand(10,10), rand(10,10)],[rand(5,10), rand(5,10)]]
f, axarr = plt.subplots(2,2)
for i in range(2):
for j in range(2):
axarr[i, j].imshow(test_data[i][j])
plt.tight_layout()
plt.subplots_adjust(wspace=0, hspace=0)
plt.show()
I've tried playing around with set_aspect and equal, but without luck.
Does anyone know how to get those gaps away?




.axis('off'). The resulting image should ideally sit tight against the figure boundaries, but I wouldn't mind if a simple solution had some space left. I don't want any gaps, so the gap isn't arbitrary, it's always 0 (if I understood your question correctly). The image sizes may change, but we can assume that one of the dimensions is always the same. - dangom