Colorbar range inconsistent in high aspect ratio images
7 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
William Thielicke
il 5 Gen 2022
Commentato: William Thielicke
il 7 Gen 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 Commenti
Risposta accettata
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)
Vedere anche
Categorie
Scopri di più su Orange in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!