how to get a color bar like shown in figure??

1 view (last 30 days)
i need a log colorbar as in figure attached. how to get that

Answers (2)

KSSV
KSSV on 12 Oct 2018
cb = colorbar();
cb.Ruler.Scale = 'log';
cb.Ruler.MinorTick = 'on';
  2 Comments
SHANMUKHA REDDY AMARAVADI
SHANMUKHA REDDY AMARAVADI on 15 Oct 2018
I forgot to mention that my data also has negative values. cb.Ruler.Scale='log'; is showing an error. I am using Matlab 2016b. my data is of large range from negative to positive. axis.Ticks range is -150000 to 100000, so when I use logspace it is only giving '0' and 'inf'.
SHANMUKHA REDDY AMARAVADI
SHANMUKHA REDDY AMARAVADI on 15 Oct 2018
Edited: SHANMUKHA REDDY AMARAVADI on 15 Oct 2018
I don't know why, but your solution didn't work for me, may be my question should be a bit more informative. I have the solution now. thank you very much for the response.

Sign in to comment.


SHANMUKHA REDDY AMARAVADI
SHANMUKHA REDDY AMARAVADI on 15 Oct 2018
Edited: SHANMUKHA REDDY AMARAVADI on 15 Oct 2018
c=logspace(min(ax1.Ticks), max(ax1.Ticks), ceil(max(ax1.Ticks)));
c1= linspace((-1)*floor(log10(abs(min(ax1.Ticks)))), ceil(log10(max(ax1.Ticks))), 6);
j=1;
for i=1:length(c1)
if c1(i) > 0
c1_Positive(j,1)=c1(i);
j=j+1;
else
c1_Negative(i,1)=abs(c1(i));
end
end
labels1=arrayfun(@(c1_Negative) ['-10^',int2str(c1_Negative)],c1_Negative,'uniformoutput',false);
set(ax1,'TickLabels',labels1);
hold on;
labels2=arrayfun(@(c1_Positive) ['10^',int2str(c1_Positive)],c1_Positive,'uniformoutput',false);
set(ax1,'TickLabels',labels2);
I am trying to display the values as 10^ for some of them and -10^ for remaining. but I am unable to do that at a time. can anyone help me?? thanks in advance.

Community Treasure Hunt

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

Start Hunting!