フィルターのクリア

How to add different titles to multiple image display using subplot?

46 ビュー (過去 30 日間)
Yuhong Jin
Yuhong Jin 2019 年 11 月 25 日
コメント済み: Image Analyst 2023 年 12 月 12 日
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 件のコメント
Image Analyst
Image Analyst 2022 年 4 月 14 日
移動済み: Dyuman Joshi 2023 年 12 月 12 日
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
Image Analyst 2023 年 12 月 12 日
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.

サインインしてコメントする。

採用された回答

Image Analyst
Image Analyst 2019 年 11 月 25 日
What you want to happen is actually what DOES happen:
I1 = imread('cameraman.tif');
I2 = imread('moon.tif');
subplot(1,2,1),imshow(I1),title('1');hold on
subplot(1,2,2),imshow(I2),title('2');hold off
0000 Screenshot.png
If you want, you can explicitly put the axes handle in:
h1 = subplot(1,2,1), imshow(I1, 'Parent', h1), title(h1, '1'); hold on
h2 = subplot(1,2,2), imshow(I2, 'Parent', h2), title(h2, '2'); hold off

その他の回答 (1 件)

dan lahat
dan lahat 2021 年 3 月 9 日
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.

Community Treasure Hunt

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

Start Hunting!

Translated by