我是Python新手,我真的很难为我的数据获得一个合理的颜色映射
我正在绘制29x29 numpy阵列,其中大多数单元为0,但平均约10-15个单元具有非零值,其范围从低10秒到数1000秒
在C++根中,你会自动得到一个漂亮的图,它有白色背景和一个漂亮的彩虹色条,你可以在下面看到。p>但是,在matplotlib中,请遵循以下建议:
python matplotlib heatmap colorbar from transparent 使用代码:
from matplotlib.colors import LinearSegmentedColormap
%matplotlib inline
#Lets visualise some events
# plot states
# plot states
# get colormap
ncolors = 256
color_array = plt.get_cmap('gist_rainbow')(range(ncolors))
# change alpha values
color_array[:,-1] = np.linspace(1.0,0.0,ncolors)
# create a colormap object
map_object = LinearSegmentedColormap.from_list(name='rainbow_alpha',colors=color_array)
# register this new colormap with matplotlib
plt.register_cmap(cmap=map_object)
# set colourbar map
cmap_args=dict(cmap='jet')
fig, axarr = plt.subplots(nrows=1, ncols=3)
axarr[0].imshow(events[0],**cmap_args)
axarr[0].set_title('Event0',fontsize=16)
axarr[0].tick_params(labelsize=16)
axarr[1].imshow(events[1],**cmap_args)
axarr[1].set_title('Event1',fontsize=16)
axarr[1].tick_params(labelsize=16)
axarr[2].imshow(events[2],**cmap_args)
axarr[2].set_title('Event2',fontsize=16)
axarr[2].tick_params(labelsize=16)
fig.subplots_adjust(right=2.0)
plt.show()
我得到了下面的图片,这是无法阅读的
请有人解释一下如何在情节的一侧获得白色背景和彩虹色条
非常感谢
要将所有零值显示为白色,可以设置'under' color。“下颜色”用于低于颜色栏中最低值的值。强制colorbar以
vmin=1
从1开始会使所有小于1的值都被视为“低于”相关问题 更多 >
编程相关推荐