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
0 个评论
采纳的回答
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 Center 和 File Exchange 中查找有关 Orange 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!