Margins of matplotlib.pyplot.imshow when used in subplot environment
<p>I am trying to plot the values of several arrays in separate plots of a figure using imshow.</p>

<p>When I plot one image only, and use the plt.imshow() command with the correct extents, the figure comes out perfectly.
However, when I try to create multiple plots of this image in the same figure, using plt.subplot(), each of these plots ends up with incorrect x-axis settings, and there are white margins. I tried correcting the x-axis range with the set_xlim() command, but it has no effect (which I also don't understand). </p>

<p>The minimal working sample is below - any help would be appreciated!</p>

<pre><code>from matplotlib import pyplot as plt
import numpy as n

image = n.array([[ 1.,  2.,  2.,  5.],
   [ 1.,  0.,  0.,  3.],
   [ 1.,  2.,  0.,  2.],
   [ 4.,  2.,  3.,  2.]])
xextent, yextent= n.shape(image)

fig, ax = plt.subplots(2,sharex=True, sharey=True)
im0 = ax[0].imshow(image, extent=(0,xextent,yextent,0),interpolation='nearest');
ax[0].set_xlim([0,4])
im1 = ax[1].imshow(image, extent=(0,xextent,yextent,0),interpolation='nearest');
ax[1].set_xlim([0,4])

plt.show()
</code></pre>

<p><a href="https://i.stack.imgur.com/eZkQa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eZkQa.png" alt="enter image description here"></a></p>