How to add different titles to multiple image display using subplot?
Show older comments
I tried to use this code below to add titles "1" and "2" to my images, but only "1" shows above the first image.
Could anyone help me with this? I want to show "1" above the first image, and "2" above the second.
Thanks in advance.
subplot(1,2,1),imshow(I1),title('1');hold on
subplot(1,2,2),imshow(I2),title('2');hold off
3 Comments
Nat
on 14 Apr 2022
Moved: Dyuman Joshi
on 12 Dec 2023
Same error with my problem. Did you find the answer?
I tried:
drawnow; figure;
imshow(Im1);
title('image 1');
drawnow; figure;
imshow(Im2);
title('image 2');
But now, the second title is now shown on the second figure but the image is printed in a separate figure.
Image Analyst
on 14 Apr 2022
Moved: Dyuman Joshi
on 12 Dec 2023
Yes, but that's not an error. Did you actually receive an error (some red text)? If so what is it?
Your code is working as expected. See below:
What did you expect would happen when it hit the "figure" command on line 4 of your code above (line 6 of my code below)?
Im1 = imread('cameraman.tif');
Im2 = imread('moon.tif');
drawnow; figure; % Create first figure window.
imshow(Im1);
title('image 1');
drawnow; figure; % Create a separate, second figure window.
imshow(Im2);
title('image 2');
Image Analyst
on 12 Dec 2023
By the way, the call to drawnow should come after you draw something, like after a call to imshow and title. Do not call it before you have even drawn anything.
Accepted Answer
More Answers (1)
dan lahat
on 9 Mar 2021
0 votes
what if I want to title two different imshow with different title. lets say
imshow(Im1);
title('image 1');
figure;
imshow(Im2);
title('image 2');
matlab is showing the two pictures but the first title has been crushed by the second one, and the second imshow has no title.
Categories
Find more on Display Image 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!

