title: Generate a heatmap in MatPlotLib
body: <p>I've been attempting to generate a heatmap by following the top answer over here: <a href="https://stackoverflow.com/questions/2369492/generate-a-heatmap-in-matplotlib-using-a-scatter-data-set">Generate a heatmap in MatPlotLib using a scatter data set</a></p>
  
  <p>With some help from you kind folk here I've shaped my data so I can mine with relative ease (though not very pretty code) the x and y coordinates.</p>
  
  <p>The coordinates are put nicely into arrays but when I plug those arrays into the heatmap code I get the following output:</p>
  
  <p><img src="https://i.stack.imgur.com/hp9hp.png" alt="enter image description here"></p>
  
  <p>The code I'm using is as follows:</p>
  
  <pre><code>import csv
  import string, numpy as np
  import numpy as np
  import numpy.random
  import matplotlib.pyplot as plt
  import pickle
  import operator as oper
  import re
  from math import sqrt
  import re # used here to remove non-numeric values
  
  
  
  file = open('P2E2D_Long_Format.csv', 'rb')
  
  reader1 = csv.reader(file, delimiter = '\t')
  non_decimal = re.compile(r'[^\d.]+')
  
  x = []
  y = []
  
  count = 0 
  
  for row in reader1:
      #print row
      if 'SCL' in row[0] and count &lt;= 5000:
          #print row[0]
          if len(row[2]) and len(row[3]) &gt; 0: #ensures that x and y CoOr are not empty.
              if '   .' not in row[2] and 'SAMPLES' not in row[3]:
                  #populates list with values in row 2 &amp; 3            
                  xCoOr = row[2]
                  yCoOr = row[3]
  
                  #this code removes the blank spaces before numbers
                  x1 = non_decimal.sub('', xCoOr)
                  y1 = non_decimal.sub('', yCoOr)
                  print x1, 'XCoOr'
                  print y1, 'YCoOr'
  
  
                  #changes values from file, that are seen as string, to a float            
                  x1 = float(x1)
                  y1 = float(y1)
                  #print x1            
                  x = x + [x1]
                  y = y + [y1]
                  count = count + 1
                  print count
  
  
  
  myarrayx = np.asarray(x)
  myarrayy = np.asarray(y)
  
  myarrayx = myarrayx - 508
  myarrayy = myarrayy - 384
  
  myarrayx = myarrayx / 100
  myarrayy = myarrayy / 100
  
  
  heatmap, xedges, yedges = np.histogram2d(myarrayx, myarrayy, bins=50)
  extent = [xedges[0], xedges[-1], yedges[0], yedges[-1]]
  plt.clf()
  plt.imshow(heatmap, extent=extent)
  plt.show()
  
  file.close()   # &lt;---IMPORTANT
  #Long_Format.close()
  #textFile.close()
  </code></pre>
  
  <p>row[0] is the Trial ID and row<a href="https://i.stack.imgur.com/YixbL.png" rel="nofollow noreferrer">2</a> is the x CoOr and row[3] the y CoOr.</p>
  
  <p>When looking at the outputted figure above it appears as though the y-axis is completely absent.</p>
  
  <p>Does anyone have any ideas?</p>
  
  <p>Here is some of the data I'm working with:</p>
  
  <pre><code>"Trial ID   Frame ID                    X-CoOr  Y-CoOr  Time"
  
  
  "SCL    5413917 PreBeep1_1st_Sketchpad  653.8   542.1   4844"
  
  "SCL    5413917 PreBeep1_1st_Sketchpad  654.7   542.2   4847"
  
  "SCL    5413919 order of frames:        655.5   541.9   4849"
  
  "SCL    5413919 order of frames:        656.1   541.2   4851"
  
  "SCL    5413921 crosshair               655.8   540.8   4851"
  
  "SCL    5413921 crosshair               655.7   540.6   4847"
  
  "SCL    5413923 sketchpad               655.7   540.6   4843"
  
  "SCL    5413923 sketchpad               655.5   540.6   4838"
  
  "SCL    5413925 sketchpad               655.3   540.7   4838"
  
  "SCL    5413925 sketchpad               655.1   540     4833"
  
  "SCL    5413927 sketchpad               655.3   538.9   4829"
  
  "SCL    5413927 sketchpad               655.4   538.1   4825"
  
  "SCL    5413929 buffer1                 655.6   537.8   4824"
  
  "SCL    5413929 buffer1                 655.5   537.5   4824"
  
  "SCL    5413931 Diode1                  655.2   537.3   4824"
  
  "SCL    5413931 Diode1                  654.9   537.6   4831"
  
  "SCL    5413931 Diode1                  654.9   538.1   4836"
  
  "SCL    5413931 Diode1                  654.8   538.6   4841"
  
  "SCL    5413931 Diode1                  654.8   539 4841"
  
  "SCL    5413931 Diode1                  655.6   539.1   4841"
  </code></pre>
  
  <p>EDIT: I have manually manipulated the min and max values on the x and y axis in the figure window as follows:
  <img src="https://i.stack.imgur.com/YixbL.png" alt="enter image description here"></p>
  
  <p>As can be seen the x-axis max value is huge. I'm not sure why this is. I suspect this value must appear in the xCoOr column in my data.</p>
  
  <p>However, even when I adjust max and min values the heatmap is blank.</p>
  
  <p>Thanks for your time on this.</p>