Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zero-value colour in matplotlib hexbin

I have some spatially-distributed data. I'm plotting this with matplotlib.pyplot.hexbin and would like to change the "background" (i.e. zero-value) colour. An example is shown below - my colour-map of choice is matplotlib.cm.jet:

Example data

How can I change the base colour from blue to white? I have done something similar with masked arrays when using pcolormesh, but I can't see anyway of doing so in the hexbin arguments. My instinct would be to edit the colourmap itself, but I've not had much experience with that.

I'm using matplotlib v.0.99.1.1

like image 940
Dave Avatar asked Mar 23 '11 09:03

Dave


1 Answers

hexbin(x,y,mincnt=1) should do the trick. Essentially, you only want to display the hexagons with more than 1 count in them.

from numpy import linspace
from numpy.random import normal
from pylab import hexbin,show

n = 2**6

x = linspace(-1,1,n)
y = normal(0,1,n)

h = hexbin(x,y,gridsize=10,mincnt=0)

gives, Bins with zero counts included

and h = hexbin(x,y,gridsize=10,mincnt=1) gives, Bin count starts at one

like image 138
lafras Avatar answered Sep 19 '22 15:09

lafras