How do I Plot images in two different figures
9 ビュー (過去 30 日間)
古いコメントを表示
In this snippet below, I want subplot 1 and 2 as a part of the same figure, which is something I am to get. I need a separate plot figure of the "%Separate side figure". I am not able to obtain that. Can you please help me out here?
Also, if I comment pause(0.000000001), my plot doesn't show up. Do you guys know why?
Thanks!
for i = 1 : length(srcFilesKinect)
axis off
filenameBL = strcat( path,'sk_left_rgb/',srcFilesBL(i).name);
I = imread(filenameBL); axis off
subplot(3,2,1), subimage(I) % Subplot 1
title( 'left')
filenameBR = strcat( path,'sk_right_rgb/',srcFilesBR(i).name);
I = imread(filenameBR); axis off
subplot(3,2,2), subimage(I) %Subplot 2
title('right')
filenameKinect = strcat( path2,srcFilesKinect(i).name);
I = imread(filenameKinect); %Separate side figure
%imshow(I);
%subplot(3,2,3), subimage(I)
image(I)
title('Demo')
fprintf('Reading %d th image\n',i)
pause(0.000000001)
end
2 件のコメント
Jan
2017 年 3 月 14 日
Do not use "path" as the name of a variable, because this shadows an important Matlab function. This can cause a very strange behavior during debugging.
Prefer fullfile instead of strcat to concatenate file names, because it cares about the separators.
回答 (2 件)
Adam
2017 年 3 月 14 日
doc figure
Just create a figure explicitly (which you should always do anyway unless you are plotting on a GUI you have created), get its axes explicitly and plot on them explicitly. e.g.
hFig = figure; hAxes = gca;
imshow( hAxes, I );
2 件のコメント
Adam
2017 年 3 月 15 日
Ah, sorry, I didn't check and thought all plotting functions had this syntax now - I never use imshow myself. Apparently imshow is still archaic so you need to use
imshow( I, 'Parent', hAxes );
Jan
2017 年 3 月 14 日
編集済み: Jan
2017 年 3 月 14 日
The pause is required to allow Matlab to update the graphics. The minimal delay is 0.01, so pause(0.000000001) does the same as pause(0.01). I'd prefer drawnow for the updating, but both work reliably.
subimage is deprecated, prefer imshow.
Do not use "path" as the name of a variable, because this shadows an important Matlab function. This can cause a very strange behavior during debugging. I've renamed to to "path1".
Prefer fullfile instead of strcat to concatenate file names, because it cares about the separators.
Then:
Axes1H = subplot(3,2,1);
title('left');
Axes2H = subplot(3,2,2);
title('right');
Fig2H = figure;
Axes3H = axes;
title('Demo');
for i = 1 : length(srcFilesKinect)
filenameBL = fullfile(path1, 'sk_left_rgb', srcFilesBL(i).name);
I = imread(filenameBL);
imshow(I, 'Parent', Axes1H);
axis off
filenameBR = fullfile(path1, 'sk_right_rgb', srcFilesBR(i).name);
I = imread(filenameBR);
imshow(I, 'Parent', Axes2H)
axis off
filenameKinect = fullfile(path2, srcFilesKinect(i).name);
I = imread(filenameKinect);
imshow(I, 'Parent', Axes3H);
axis off
fprintf('Reading %d th image\n', i);
drawnow;
end
There will be better names than the counted "Axes1H", something more meaningful. Indices inside names of variables are a bad idea.
2 件のコメント
Jan
2017 年 3 月 15 日
After
Fig2H = figure;
Axes3H = axes;
Axes3H is a valid axes handle. It can only get invalid, if this axes is deleted, e.g. by clf or a similar command, or if its figure is deleted.
参考
カテゴリ
Help Center および File Exchange で Subplots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!