对数刻度颜色条:如何设置刻度?
log sacle colorbar: how to set ticks?
我想将颜色条的刻度设置为对数刻度,具有简单易读的刻度:2 3 4 5 6 7 8 9 10 20 30(而不仅仅是“10^0”、“10^1 ");
例如我这样做:
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]);
这样不行。怎么做?
您的代码运行良好,符合预期。如果你检查你的颜色条,下限值为 22,因此你只能看到最后一个标签。
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]);
我想将颜色条的刻度设置为对数刻度,具有简单易读的刻度:2 3 4 5 6 7 8 9 10 20 30(而不仅仅是“10^0”、“10^1 ");
例如我这样做:
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]);
这样不行。怎么做?
您的代码运行良好,符合预期。如果你检查你的颜色条,下限值为 22,因此你只能看到最后一个标签。
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]);