matplotlib hexbin 中的零值颜色 [英] Zero-value colour in matplotlib hexbin

查看:35
本文介绍了matplotlib hexbin 中的零值颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些空间分布的数据.我正在用 matplotlib.pyplot.hexbin 绘制它并想更改背景"(即零值)颜色.下面是一个示例-我选择的颜色图是 matplotlib.cm.jet :

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:

如何将基色从蓝色更改为白色?使用 pcolormesh 时,我对遮罩数组执行了类似的操作,但是在 hexbin 参数中却看不到这样做.我的直觉是编辑颜色图本身,但我对此没有太多经验.

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.

我正在使用matplotlib v.0.99.1.1

I'm using matplotlib v.0.99.1.1

推荐答案

hexbin(x,y,mincnt=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)

给,

h = hexbin(x,y,gridsize = 10,mincnt = 1)给出,

这篇关于matplotlib hexbin 中的零值颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆