Colorbar range inconsistent in high aspect ratio images
7 views (last 30 days)
Show older comments
William Thielicke
on 5 Jan 2022
Commented: William Thielicke
on 7 Jan 2022
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 Comments
Accepted Answer
Steve Eddins
on 5 Jan 2022
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.
More Answers (0)
See Also
Categories
Find more on Orange in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!