区分正值和负值的颜色图 [英] Colorplot that distinguishes between positive and negative values

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

问题描述

在此示例代码中可以看到,因为0在频谱中某处,所以很难跟踪哪些点是负的,哪些点是正的.尽管我的真实情节比较连续,但我想知道是否有办法在这些克洛普尔图中分开负值和正值.例如,我如何为正值和负值使用两种不同的颜色光谱.

As one can see in this sample code since 0 is somewhere in the spectrum it is hard to trace which points are negative and which are positive. Although my real plot is more contiguous I wonder if there is a way to seperate negative and postivie values in these clorplots; for example how can I use two different spectrum of colours for positive and negative values.

import numpy as np
from matplotlib import pyplot as plt
a=np.random.randn(2500).reshape((50,50))
plt.imshow(a,interpolation='none')
plt.colorbar()
plt.show()

编辑在@MultiVAC的帮助下,并寻找解决方案时,我遇到了.

EDIT With the help of @MultiVAC and looking for solutions I came across this.

import numpy as np
from matplotlib import pyplot as plt
from matplotlib.colors import BoundaryNorm
a=np.random.randn(2500).reshape((50,50))

# define the colormap
cmap = plt.cm.jet
# extract all colors from the .jet map
cmaplist = [cmap(i) for i in range(cmap.N)]
# create the new map
cmap = cmap.from_list('Custom cmap', cmaplist, cmap.N)

# define the bins and normalize
bounds = np.linspace(np.min(a),np.max(a),5)
norm = BoundaryNorm(bounds, cmap.N)

plt.imshow(a,interpolation='none',norm=norm,cmap=cmap)
plt.colorbar()
plt.show()

我还是不知道如何区分零!

Still I don't know how to differentiate zero!

推荐答案

确定以供将来参考.正如@tcaswell 建议的那样,我使用发散图作为其中的一部分.你可以看看上面的链接.

Ok for the future reference. I used diverging maps as part of it as @tcaswell suggested. You can look to the above links.

import numpy as np
from matplotlib import pyplot as plt
from matplotlib.colors import BoundaryNorm
a=np.random.randn(2500).reshape((50,50))

# define the colormap
cmap = plt.get_cmap('PuOr')

# extract all colors from the .jet map
cmaplist = [cmap(i) for i in range(cmap.N)]
# create the new map
cmap = cmap.from_list('Custom cmap', cmaplist, cmap.N)

# define the bins and normalize and forcing 0 to be part of the colorbar!
bounds = np.arange(np.min(a),np.max(a),.5)
idx=np.searchsorted(bounds,0)
bounds=np.insert(bounds,idx,0)
norm = BoundaryNorm(bounds, cmap.N)

plt.imshow(a,interpolation='none',norm=norm,cmap=cmap)
plt.colorbar()
plt.show()

这篇关于区分正值和负值的颜色图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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