title: Extent and aspect; square pixels in an image with shared axis in matplotlib
body: <p>I am stuck in a rather complicated situation. I am plotting some data as an image with imshow(). Unfortunately my script is long and a little messy, so it is difficult to make a working example, but I am showing the key steps. This is how I get the data for my image from a bigger array, written in a file:</p>
  
  <pre><code>data = np.tril(np.loadtxt('IC-heatmap-20K.mtx'), 1)
  #
  #Here goes lot's of other stuff, where I define start and end
  #
  chrdata = data[start:end, start:end]
  chrdata = ndimage.rotate(chrdata, 45, order=0, reshape=True, 
                           prefilter=False, cval=0)
  ax1 = host_subplot(111) 
  #I don't really need host_subplot() in this case, I could use something more common;
  #It is just divider.append_axes("bottom", ...) is really convenient.
  plt.imshow(chrdata, origin='lower', interpolation='none',
             extent=[0, length*resolution, 0, length*resolution]) #resolution=20000
  </code></pre>
  
  <p>So the values I am interested in are all in a triangle with the top angle in the middle of the top side of a square. At the same time I plot some data (lot's of coloured lines in this case) along with the image near it's bottom.
  <img src="https://i.stack.imgur.com/Re2EZ.png" alt="with extent without aspect"></p>
  
  <p>So at first this looks OK, but is actually is not: all pixels in the image are not square, but elongated with their height being bigger, than their width. This is how they look if I zoom in:
  <img src="https://i.stack.imgur.com/vdo8d.png" alt="pixels with extent without aspect"></p>
  
  <p>This doesn't happen, If I don't set extent when calling imshow(), but I need it so that coordinates in the image and other plots (coloured lines at the bottom in this case), where identical (see <a href="https://stackoverflow.com/questions/23333671/converting-coordinates-of-a-picture-in-matplotlib">Converting coordinates of a picture in matplotlib?</a>).
  I tried to fix it using aspect. I tried to do that and it fixed the pixels' shape, but I got a really weird picture:
  <img src="https://i.stack.imgur.com/0eBGA.png" alt="extent and aspect"></p>
  
  <p>The thing is, later in the code I explicitly set this:</p>
  
  <pre><code>ax1.set_ylim(0*resolution, length*resolution) #resolution=20000
  </code></pre>
  
  <p>But after setting aspect I get absolutely different y limits. And the worst thing: ax1 is now wider, than axes of another plot at the bottom, so that their coordinates do not match anymore! I add it in this way:</p>
  
  <pre><code>axPlotx = divider.append_axes("bottom", size=0.1, pad=0, sharex=ax1)
  </code></pre>
  
  <p>I would really appreciate help with getting it fixed: square pixels, identical coordinates in two (or more, in other cases) plots. As I see it, the axes of the image need to become wider (as aspect does), the ylims should apply and the width of the second axes should be identical to the image's.
  Thanks for reading this probably unclear explanation, please, let me know, if I should clarify anything.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>As suggested in the comments, I tried to use </p>
  
  <pre><code>ax1.set(adjustable='box-forced')
  </code></pre>
  
  <p>And it did help with the image itself, but it caused two axes to get separated by white space. Is there any way to keep them close to each other?</p>
  
  <p><img src="https://i.stack.imgur.com/Ae8oj.png" alt="extent, aspect and box-forced"></p>