Coloring the heat map of the histogram by height in Matlab

clear
clc
%数据
original=[0,0;1,0;2,0.0100000000000000;3,0.0100000000000000;4,0.0200000000000000;5,0.0600000000000000;6,0.0720000000000000;7,0.0730000000000000;8,0.0840000000000000;9,0.0850000000000000;10,0.0860000000000000;11,0.0870000000000000;12,0.0500000000000000;13,0.0100000000000000;14,0.0100000000000000;15,0.0100000000000000;16,0.0600000000000000;17,0.112000000000000;18,0.125000000000000;19,0.133000000000000;20,0.134000000000000;21,0.136000000000000;22,0.136000000000000;23,0.137000000000000;24,0.0900000000000000;25,0.0500000000000000;26,0.0200000000000000;27,0.0100000000000000;28,0.0600000000000000;29,0.130000000000000;30,0.151000000000000;31,0.152000000000000;32,0.153000000000000;33,0.154000000000000;34,0.173000000000000;35,0.180000000000000;36,0.183000000000000;37,0.185000000000000;38,0.193000000000000;39,0.195000000000000;40,0.210000000000000;41,0.160000000000000;42,0.153000000000000;43,0.120000000000000;44,0.0900000000000000;45,0.0600000000000000;46,0.0530000000000000;47,0.0300000000000000;48,0;49,0;50,0;51,0;52,0];
%画直方图
h = bar(original(:,2),1)
%设置用于着色的CData
h.CData = original(:,2);
%将直方图的FaceColor属性设置为flat,这样就可以用CDate里的数据进行热力图着色
h.FaceColor = 'flat'
%设置热力图的数值范围
caxis([0 0.25])
%显示色标
colorbar
%设置热力图的模式
colormap('cool');

The result of the drawing:

1
Set the colormap to the'parula' mode: The
2
colormap selectable modes are:
3

Reference document:
https://ww2.mathworks.cn/help/matlab/colors-1.html?s_tid=CRUX_lftnav

Guess you like

Origin blog.csdn.net/weixin_43795921/article/details/108745167