Displaying colorbar shrinks displayed image.
이전 댓글 표시
I would like to have two images of the same size, side-by-side, but with the image on the right having a colorbar next to it. I can have two images side by side with the same size, however when I display the colorbar on one image, that image suddenly shrinks. Questions:
- Why does this shrinking happen?
- Is there any way to prevent it from happening?
- If not, is there anyway I can undo the shrinkage once it has happened?
By the way, this shrinking happens both in a simple m-file script (like below) as well as in my AppDesigner app that has two axes placed on the GUI.
Minimum code to demonstrate the problem:
% Read in standard demo image.
fileName = 'peppers.png';
rgbImage = imread(fileName);
% Display image in two axes, side-by-side.
ax1 = subplot(1, 2, 1);
img1 = imshow(rgbImage);
ax2 = subplot(1, 2, 2);
img2 = imshow(rgbImage);
% At this point they're equal size.
% Calling colorbar will shrink the right hand side image.
colorbar; % This immediately shrinks the right hand side image.
% Print out the various position values to see where they differ.
% The format is [xLeft, yTop, width, height].
ax1.Position
ax2.Position
ax1.OuterPosition
ax2.OuterPosition
ax1.InnerPosition
ax2.InnerPosition
% Try to change size (enlarge width and height) of ax2 to match ax1.
% (It doesn't work);
ax2.OuterPosition(3) = ax1.OuterPosition(3);
ax2.OuterPosition(4) = ax1.OuterPosition(4);
ax2.InnerPosition(3) = ax1.InnerPosition(3);
ax2.InnerPosition(4) = ax1.InnerPosition(4);
If I try to change image1 to match image2:
% Change size (width and height) of ax1 to match ax2.
% (Now both images are shrunken);
ax1.OuterPosition(3) = ax2.OuterPosition(3)
ax1.OuterPosition(4) = ax2.OuterPosition(4)
ax1.InnerPosition(3) = ax2.InnerPosition(3)
ax1.InnerPosition(4) = ax2.InnerPosition(4)
That works, but unfortunately now both images are tiny and there is a ton of gray space around the images. Is there any way to have both images the original/larger size?
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Colorbar에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




