title: matplotlib heatmap reversing data?
body: <p>This is a weird one, hope someone can help me.  I'm trying to do a density plot of my data with matplotlib heatmap, but somehow my data is getting reversed/rotated in a strange way.  I have a scatterplot and then I'm binning those points for density, but the image is not at all what should be coming out.  For example, here's the original scatter plot, which has the correct orientation: </p>
  
  <p><img src="https://i.stack.imgur.com/6DUGS.jpg" alt="original scatter plot"></p>
  
  <p>Then here's my heatmap (notice that the structure is rotated 90 degrees counterclockwise from above, but that the axis data is correct... the numbers on the axes are generated automatically from the data, so if you simply reverse the axes the picture comes out correctly but the numbers are all off):</p>
  
  <p><img src="https://i.stack.imgur.com/SMHF4.jpg" alt="heatmap with wrong orientation, but correct axes"></p>
  
  <p>I just can't see how this could be, since the data parsing routine is identical to what it was before when I just generated the scatter plot.  It has to be something in the way the heatmap plot is coded, I would think, but I don't see where the breakdown could be.  I've already tried accounting for the built-in origin placement (upper-left corner) for the heatmap, that doesn't solve it.  The code is as follows (first all the data parsing):</p>
  
  <pre><code>import numpy as np
  from numpy import ndarray
  import matplotlib.pyplot as plt
  import matplotlib
  import atpy
  from pylab import *
  
  twomass = atpy.Table()
  
  twomass.read('/Raw_Data/IRSA_downloads/2MASS_GCbox2.tbl')
  
  
  hmag = list([twomass['h_m']])
  jmag = list([twomass['j_m']])
  hmag = np.array(hmag)
  jmag = np.array(jmag)
  colorjh = np.array(jmag - hmag)
  
  idx_c = (colorjh &gt; -1) &amp; (colorjh &lt; 6)  #manipulate desired color quantities here
  idx_h = (hmag &gt; 8) &amp; (hmag &lt; 18)
  idx = idx_c &amp; idx_h
  </code></pre>
  
  <p>Now here's the heatmap code:</p>
  
  <pre><code>heatmap, xedges, yedges = np.histogram2d(colorjh[idx], hmag[idx], bins=500)
  extent = [xedges[0], xedges[-1], yedges[0], yedges[-1]]
  
  plt.clf()
  plt.imshow(heatmap, extent=extent)
  
  plt.xlabel('Color(J-H)', fontsize=15)           #adjust axis labels here
  plt.ylabel('Magnitude (H)', fontsize=15)
  
  plt.gca().invert_yaxis()
  
  plt.legend(loc=2)
  plt.title('CMD for Galactic Center (2MASS)', fontsize=20)
  plt.grid(True)
  plt.show()
  </code></pre>
  
  <p>I'm pretty new to Python, so the less jargony the explanation, the more likely I'll be able to put it to good use.  Thanks for any help y'all can provide.</p>