Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I set dataless areas of a hist2d plot to the zero-value color?

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?
like image 776
Louis Thibault Avatar asked Apr 14 '13 13:04

Louis Thibault


1 Answers

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

like image 143
Louis Thibault Avatar answered Oct 23 '22 20:10

Louis Thibault