Search code examples
imagematlabmatlab-figuresubplot

Colorbar resizes the subplots


I'm trying to plot 3 images side by side in MATLAB using subplot:

maxValue =  9;
minValue =  5;

figure(1)
subplot(1,3,1);
imshow(im1);
axis equal;

subplot(1,3,2);
imagesc(im2);colorbar;
caxis([minValue maxValue]) 
axis equal;

subplot(1,3,3);
imagesc(im3);colorbar;
caxis([minValue maxValue]) 
axis equal;

but the result looks like this:

results

Apparently the colorbar is resizing the image. How can I make all 3 images the same size and the colorbar fit the size of the image?


Solution

  • Your image is resized to maintain its aspect ratio according to the available space.
    Use axis normal; for subplot(1,3,1) instead of axis equal.
    You might need to maximise the figure window as well.


    For im1 = imread('peppers.png');, the result is:

    output