title: creating heatmap in python
body: <p>I'm wondering if someone can help me with the following. I have some data in the form of x- and y-coordinates, and I want to make a heatmap i.e. time spent looking at the specific coordinates. It is quite a lot of data, so I'm linking to an example of it here in my gdrive (<a href="https://drive.google.com/open?id=1BWJWPbUFkr-0v5n9XcrWpJOZE4-0iqxIC5nJQ3y0p1w" rel="nofollow noreferrer">here</a>). </p>
  
  <p>Using Jurgy's answer from this post (<a href="https://stackoverflow.com/questions/2369492/generate-a-heatmap-in-matplotlib-using-a-scatter-data-set">here</a>), I've made the following code:</p>
  
  <pre><code>import numpy as np
  import pandas as pd
  import matplotlib.pyplot as plt
  import matplotlib.cm as cm
  from scipy.ndimage.filters import gaussian_filter
  
  # get the data
  df = pd.read_csv(r'C:\Users\L\Desktop\df.csv')
  x, y  = df['x'], df['y']
  
  # remove zero values because these are not supposed to be ther.
  x = x[x &gt; 0]
  y = y[y &gt; 0]
  
  # function from linked SO question
  # I edited the bins argument
  def myplot(x, y, s, bins=(1280, 768)):
      heatmap, xedges, yedges = np.histogram2d(x, y, bins=bins)
      heatmap = gaussian_filter(heatmap, sigma=s)
  
      '''i have tried editing this to be:
      extent = [0, 1280, 0, 768]#, but this just seems to 
      rescale everything, fitting it to within the space
      and it no longer represents the correct regions/coordinates.'''
      extent = [xedges[0], xedges[-1], yedges[0], yedges[-1]]
  
      return heatmap.T, extent
  
  sigma = 32
  img, extent = myplot(x, y, sigma)
  
  plt.imshow(img, extent=extent, cmap=cm.jet)
  #plt.xlim(0, 1280)
  #plt.ylim(0, 768)
  plt.colorbar()
  ''' I also tried to define xlims and ylims.
   this positions it correctly, but there
   is a lot of bounding whitespace. The only way 
   I can think to solve that is to append some
   values to the x- and y-coordinates to include
   the limits like:
  xlims, ylims = pd.Series([0, 1280]), pd.Series([0, 768])
  x, y = x.append(xlims), y.append(ylims)
  x.reset_index(inplace=True, drop=True)
  y.reset_index(inplace=True, drop=True)
  but it also doesn't work...'''
  </code></pre>
  
  <p>And this gives me the following nice result:
  <a href="https://i.stack.imgur.com/3tOrb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3tOrb.png" alt="enter image description here"></a></p>
  
  <p>I know this seems to be exactly what I want to see in terms of the "shape" of the data. But I have some issues:
  1. My data represents a computer monitor screen with resolution 1280x768, so I need the plot to reflect this and I can't seem to get that right - as you can see from the comments in the code. In this way I need the plot to be as large as the following, but obviously without the whitespace:
  <a href="https://i.stack.imgur.com/W000q.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/W000q.png" alt="enter image description here"></a></p>
  
  <ol start="2">
  <li>I also wanted the scale to be different (I don't even know what scale this is at the moment). Each row of x- and y-data represent approx ~16.6667 ms (the data acquisition rate), and I want it to be scaled based on the time (ms) in each coordinate. At the moment the colour scale is from 0 to 0.08 and I'm not sure where this is coming from. I would expect the scale to be more like 0 to 2000 or so.</li>
  </ol>