2011-03-23 99 views
11

我有一些空间分布的数据。我正在用matplotlib.pyplot.hexbin进行绘图,并且想要改变“背景”(即零值)颜色。一个例子如下所示: - 选择我的彩图是matplotlib.cm.jetmatplotlib hexbin中的零值颜色

Example data

如何从蓝色底色改为白色?在使用pcolormesh时,我已经做了一些与掩码数组类似的处理,但是在hexbin参数中我无法看到这样做。我的直觉是编辑色彩映射本身,但我没有太多的经验。

我使用matplotlib v.0.99.1.1

回答

16

hexbin(x,y,mincnt=1)应该做的伎俩。基本上,你只想显示其中有多于一个计数的六边形。

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) 

给人, Bins with zero counts included

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

+0

太好了!我不知道我是怎么错过了这个arg,它在pydoc中就是那么简单!谢谢 – Dave 2011-03-25 11:49:29

+0

@Dave:没问题。我花了一段时间才弄清楚了。 – lafras 2011-03-25 12:25:12