10

I'm tracking a subject's gaze over a specified area of a computer screen. I'm constructing gaze heatmaps using pyplot's hist2d function.

Here's a simple example:

figure()
hist2d(xval, yval, bins=1000)
xlim([-6, 6])
ylim([-4.5, 4.5])

enter image description here

As you can see, there is a significant area outside of the range of my data. However, I would like to set this area to the blue indicative of a zero-value.

My first attempt using imshow can be seen here:

figure()
imshow(np.array([[0] * 8] * 12), extent=[-6, 6, -4.5, 4.5])
hist2d(xval, yval, bins=1000)
xlim([-6, 6])
ylim([-4.5, 4.5])

enter image description here

This sort of works, but leaves an ugly vertical line at the boundary of my data's range.

My questions are as follows:

  1. Is there a way to fill the figure with the zero-value blue while avoiding the imshow call
  2. If not, how can I hide the vertical line?
Louis Thibault
  • 20,240
  • 25
  • 83
  • 152
  • White area is intentional because no data is essentially null, not 0. I think the best solution would be to extend the data you are plotting. – sashkello Apr 14 '13 at 13:23
  • @sashkello, yes, I realize the white area is null, hence my question. I don't see how I could extend the data without denaturing it. My question *is*, "how do I extend it". – Louis Thibault Apr 14 '13 at 13:28
  • If it is a question of visualization, I don't see a point in getting into much trouble with it - just have a temporary modified data set for plotting. – sashkello Apr 14 '13 at 13:31
  • @shashkello, I understand, but my problem is that I don't see how I would go about modifying the dataset. Histograms count occurrences of data, so in order for there to be a zero-value, there needs to **not** be data. I believe that `hist2d` whites out all coordinates outside of the maximum value in each dimension. In the meantime, I've figured it out. I need only mess with the `range` kwarg. – Louis Thibault Apr 14 '13 at 13:36
  • @sashkello Modifying data just for plotting starts to run it to ethical issues _real_ fast. In this case padding out with zeros may be reasonable, but it is still a bad attitude to have. The first responsibility of a graph is to be _accurate_, everything else is secondary. – tacaswell Apr 14 '13 at 16:34
  • @blz You might want to look into using other color maps, `cubehelix` is participatory nice and might work for your data. – tacaswell Apr 14 '13 at 16:36
  • @tcaswell, Thanks for the suggestion! These graphs were prototypes, but I was thinking of looking at other color maps because the small values aren't readily visible. Your suggestion is most welcome, and I'll check out `cubehelix`! I also second your opinion on transforming data for plotting purposes -- one should transform data in order answer a question -- the graph should make that answer legible. – Louis Thibault Apr 14 '13 at 18:46

1 Answers1

14

Okay, I've figured it out. It's actually rather simple: one just needs to manipulate the range kwarg.

figure()
#imshow(np.array([[0] * 8] * 12), extent=[-6, 6, -4.5, 4.5])
hist2d(xval, yval, bins=1000, range=np.array([(-6, 6), (-4.5, 4.5)]))
xlim([-6, 6])
ylim([-4.5, 4.5])

enter image description here

Louis Thibault
  • 20,240
  • 25
  • 83
  • 152