Colorbar range inconsistent in high aspect ratio images

7 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Steve Eddins
Steve Eddins il 5 Gen 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.

Più risposte (0)

Prodotti


Release

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by