开发者

Zero-value colour in matplotlib hexbin

开发者 https://www.devze.com 2023-02-18 23:29 出处:网络
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

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:

Zero-value colour in matplotlib hexbin

开发者_Python百科

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


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,

Zero-value colour in matplotlib hexbin

and h = hexbin(x,y,gridsize=10,mincnt=1) gives,

Zero-value colour in matplotlib hexbin

0

精彩评论

暂无评论...
验证码 换一张
取 消