how to change colorbar's color to continuous

19 次查看(过去 30 天)
Hi, I generated the following plot:
But the colorbar ticks are not corresponds to each color. For example, 2 is inside of one color. Is it possible to change the colorbar to continuous?
Also, my matrix does not have negative values. I would like to use more levels of red colors to describe my data and only one level of blue for show negative.
Here is my code:
A=readtable('data.csv');
B=table2array(A(:,2:end));
heatmap_obj=HeatMap(B,'Colormap',redbluecmap)
h=plot(heatmap_obj)
hcb=colorbar(h);
Data is attached.

采纳的回答

Ameer Hamza
Ameer Hamza 2018-5-8
编辑:Ameer Hamza 2018-5-8
This is happening because you are using matrix redbluecmap as the color map, and this matrix only contains 11 colors. Either run the code with default colormap like this
heatmap_obj=heatmap(B)
or increase the number of colors in redbluecmap.
Edit:
the final code after discussion in comment is:
A=readtable('data.csv');
B=table2array(A(:,2:end));
cmap = redbluecmap;
newCmap = imresize(cmap, [64, 3]); % original color map contain just 11 colors, this increase it to 64
newCmap = min(max(newCmap, 0), 1);
heatmap_obj=HeatMap(B,'Colormap', newCmap);
h=plot(heatmap_obj);
hcb=colorbar(h);
  6 个评论
Li Xue
Li Xue 2018-5-8
编辑:Li Xue 2018-5-8
It looks great! Many thanks.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Colormaps 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by