title: how to make square subplots in matplotlib with heatmaps?
body: <p>I'm trying to make a simple subplot with a dendrogram in one subplot and a heat map in another, while maintaining square axes. I try the following:</p>
  
  <pre><code>from scipy.cluster.hierarchy import linkage
  from scipy.cluster.hierarchy import dendrogram
  from scipy.spatial.distance import pdist
  
  fig = plt.figure(figsize=(7,7))
  plt.subplot(2, 1, 1)
  cm = matplotlib.cm.Blues
  X = np.random.random([5,5])
  pmat = pdist(X, "euclidean")
  linkmat = linkage(pmat)
  dendrogram(linkmat)
  plt.subplot(2, 1, 2)
  labels = ["a", "b", "c", "d", "e", "f"]
  Y = np.random.random([6,6])
  plt.xticks(arange(0.5, 7.5, 1))
  plt.gca().set_xticklabels(labels)
  plt.pcolor(Y)
  plt.colorbar()
  </code></pre>
  
  <p>this yields the following:</p>
  
  <p><img src="https://i.stack.imgur.com/isUZo.png" alt="enter image description here"></p>
  
  <p>but the problems are that the axes are not square, and the colorbar is considered part of the second subplot. I'd like it instead to hang outside the plot, and make it so the dendrogram box and the heatmap box are both square and aligned with each other (i.e. same size.)</p>
  
  <p>I tried using <code>aspect='equal'</code> to get square axes when calling <code>subplot</code> as the documentation suggests, but this ruined the plot, giving this...</p>
  
  <p><img src="https://i.stack.imgur.com/cRZYj.png" alt="enter image description here"></p>
  
  <p>if I try to use <code>plt.axis('equal')</code> after each subplot instead of <code>aspect='equal'</code>, it strangely squares the heatmap but not its bounding box (see below), while destroying the dendrogram altogether and also messing up the alignment of the xtick labels.... - giving rise to this mess:</p>
  
  <p><img src="https://i.stack.imgur.com/L8X1V.png" alt="enter image description here"></p>
  
  <p>how can this be fixed? to summarize, I'm trying to plot something very simple: a square dendrogram in the top subplot, and a square heatmap in the bottom subplot, with the color bar on the right. nothing fancy.</p>
  
  <p>finally, more general question: is there a general rule / principle to follow to force matplotlib to <em>always</em> make axes square? I cannot think of a single case where I don't want square axes but it's usually not the default behavior. I'd like to force all plots to be square if possible.</p>