How to set the diagonal areas of hist2d plot to zero color?

I track an objective look at a specific area of ​​the computer screen. I am building shortcuts using the pyplot hist2d function.

Here is 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 the range of my data. However, I would like to set this area to blue by specifying a zero value.

My first attempt with 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 kind of work, but leaves an ugly vertical line at the edge of my data range.

My questions are as follows:

  • Is there a way to fill the shape with a blue zero value avoiding calling imshow
  • If not, how to hide the vertical line?
+6
source share
1 answer

Ok, I figured it out. This is actually quite simple: you just need to manipulate 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

+6
source

All Articles