Clear Filters
Clear Filters

how to change colorbar's color to continuous

24 views (last 30 days)
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.

Accepted Answer

Ameer Hamza
Ameer Hamza on 8 May 2018
Edited: Ameer Hamza on 8 May 2018
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 Comments
Li Xue
Li Xue on 8 May 2018
Edited: Li Xue on 8 May 2018
It looks great! Many thanks.

Sign in to comment.

More Answers (0)

Categories

Find more on Colormaps in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!