I want to set the ticks of the colorbar to be in log scale, with simple readable ticks: 2 3 4 5 6 7 8 9 10 20 30 (and not just "10^0", "10^1");
for example I do:
x = linspace(0,0.9);
y=logspace(-1,1);
[X,Y] = meshgrid(x,y);
Z = 220 *sqrt((1-X).*Y); %just random function(x,y)
[M,c]= contourf(X,Y,Z,100);
c.LineColor = 'none';
set(gca,'ColorScale','log')
cl=colorbar;
ylabel(cl, 'color')
cl.Ticks=[ 2 3 4 5 6 7 8 9 10 20 30];
cl.TickLabels = num2cell([ 2 3 4 5 6 7 8 9 10 20 30]);
It doesn't work that way. How to do it?
CodePudding user response:
Your code works well and as expected. If you check your colorbar, the lower limit value is 22, and therefore you only see the last label.
x = linspace(0,0.9);
y=logspace(-1,1);
[X,Y] = meshgrid(x,y);
Z = 220 *sqrt((1-X).*Y); %just random function(x,y)
[M,c]= contourf(X,Y,Z,100);
c.LineColor = 'none';
set(gca,'ColorScale','log')
cl=colorbar;
ylabel(cl, 'color')
cl.Limits=[2 cl.Limits(2)] % change the range
cl.Ticks=[ 2 3 4 5 6 7 8 9 10 20 30];
cl.TickLabels = num2cell([ 2 3 4 5 6 7 8 9 10 20 30]);