Need help regarding colorbar?

조회 수: 2 (최근 30일)
Lavnish Gupta
Lavnish Gupta 2018년 6월 17일
댓글: Ameer Hamza 2018년 6월 18일
I want to create a colorbar with three colors: blue color for minimum( it will be negative), white color for zero(in the middle) and red color for maximum(it will be positive). I want the colorbar to transform smoothly between the three colors. Any suggestions?
  댓글 수: 2
Rik
Rik 2018년 6월 17일
Create a colormap that is sufficiently smooth to your liking (e.g. with a few calls to linspace). Then you can set the Ticks property and the TickLabels property. The nice thing for you is that if you choose your scale sufficiently small, all negative values will be below the lowest index (and be colored with the lowest index), and all positive values will be above the highest index (which will be colored with the highest index). That would leave only 0 itself to be colored white.
You should supply a MWE, so we can help you tweak your code to solve this for realistic values. (Use the {}Code button to correctly format your code.)
Lavnish Gupta
Lavnish Gupta 2018년 6월 18일
I know how to set the maximum and minimum values for colobar using:
caxis([min max]);
I have a colorbar which I got from fileexchange. I have set the length to 51 units:
colormap(redblue(51));
My colorbar has three colors: red and blue at the edges and white in middle. I want to set my middle white color value to 0 exactly at the center.

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

채택된 답변

Ameer Hamza
Ameer Hamza 2018년 6월 18일
If you want white color exactly at the center corresponding to value 0 then you will need to make the limit of caxis() symmetrical around zero. I suppose that in your case min value is negative. Therefore try
maxLimit = max(abs(min), abs(max));
caxis([-maxLimit maxLimit]);
  댓글 수: 2
Lavnish Gupta
Lavnish Gupta 2018년 6월 18일
Hi Ameer,
I tried it and it worked perfectly as required. Thanks!
Ameer Hamza
Ameer Hamza 2018년 6월 18일
You are welcome.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Color and Styling에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by