Colorbar range inconsistent in high aspect ratio images

7 次查看(过去 30 天)
Hi, I am certainly doing sth wrong, but I wonder why Matlab displays different colormap limits when I change the colormap location from 'East' to 'North'. Any ideas...?
%incorrect colorbar scale for images with high aspect ratio:
%Note that in figure 1, the colormap range is only from 1 to 125 which is incorrect
close all
clear
clc
A=floor(rand(1000,200)*255);
locations={'North','East'};
for location =1:2
figure
imagesc(A)
coloobj=colorbar (locations{location},'FontWeight','bold','Fontsize',12,'color','k');
set(coloobj,'XTickLabel',num2str(get(coloobj,'XTick')','%5.5g')) %Trying to change display format <--- This is the reason for the issue. But why?
set(coloobj,'YTickLabel',num2str(get(coloobj,'YTick')','%5.5g'))
axis image;
end
%No problems with low aspect ratio:
A=floor(rand(400,400)*255);
locations={'North','East'};
for location =1:2
figure
imagesc(A)
coloobj=colorbar (locations{location},'FontWeight','bold','Fontsize',12,'color','k');
set(coloobj,'XTickLabel',num2str(get(coloobj,'XTick')','%5.5g')) %Trying to change display format <--- This is the reason for the issue. But why?
set(coloobj,'YTickLabel',num2str(get(coloobj,'YTick')','%5.5g'))
axis image;
end

采纳的回答

Steve Eddins
Steve Eddins 2022-1-5
Call axis image before you create the colorbar and set its tick labels. When you set tick labels manually, a mode is set so that the tick labels will not be automatically changed later. In the code as you have it, the tick labels are being set based on the aspect ratio that is in place before the axis image call, and then they stay fixed and do not respond to the changes produced by the axis image call.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Orange 的更多信息

标签

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by