필터 지우기
필터 지우기

how to change colorbar's color to continuous

조회 수: 24 (최근 30일)
Li Xue
Li Xue 2018년 5월 8일
댓글: Ameer Hamza 2018년 5월 8일
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.
Ameer Hamza
Ameer Hamza 2018년 5월 8일
You are welcome.

댓글을 달려면 로그인하십시오.

추가 답변 (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