How can I put existing figures in different subplots in another figure in MATLAB 6.5 (R13)?
264 ビュー (過去 30 日間)
古いコメントを表示
MathWorks Support Team
2010 年 9 月 8 日
コメント済み: Walter Roberson
2023 年 8 月 25 日
I want to make several plots, each in their own figure. I then want to create a final figure which contains subplots which have the contents of the original figures.
採用された回答
MathWorks Support Team
2010 年 9 月 8 日
The ability to make subplots from a set of figures interactively has been incorporated in MATLAB 7.2 (R2006a) using 'Plot Tools'. To do this, perform the following steps:
1. Plot a figure.
2. Click on the white icon, "Show Plot Tools and dock figure", on the top of the figure.
3. Select all objects by pressing CTRL-A
4. Copy the objects by pressing CTRL-C
5. Open a new figure window in Plot Tools by clicking on the white icon, "New Figure" on the left.
6. Paste the objects by pressing CTRL-V
7. Repeat the steps 1-4 for the other figures you want to copy and paste them into the final figure.
The sub-plots in the final figure can now be resized and moved as desired.
To work around this issue in previous releases, read the following:
The COPYOBJ function will allow you to copy objects between parent objects. In order to copy several sets of axes into a subplot, you will need to use two steps:
1. Copy the contents of your original figure into your destination figure.
2. Modify the position properties of the axes so that they match a subplot's position. Following is an example code which should help you to set the position property. This code is designed only to work with a 4-by-1 set of subplots. You may need to modify the code to work with your data.
% First, create 4 figures with four different graphs (each with a
% colorbar):
figure(1)
surf(peaks(10))
colorbar
figure(2)
mesh(peaks(10))
colorbar
figure(3)
contour(peaks(10))
colorbar
figure(4)
pcolor(peaks(10))
colorbar
% Now create destination graph
figure(5)
ax = zeros(4,1);
for i = 1:4
ax(i)=subplot(4,1,i);
end
% Now copy contents of each figure over to destination figure
% Modify position of each axes as it is transferred
for i = 1:4
figure(i)
h = get(gcf,'Children');
newh = copyobj(h,5)
for j = 1:length(newh)
posnewh = get(newh(j),'Position');
possub = get(ax(i),'Position');
set(newh(j),'Position',...
[posnewh(1) possub(2) posnewh(3) possub(4)])
end
delete(ax(i));
end
figure(5)
2 件のコメント
Walter Roberson
2023 年 8 月 25 日
@Megna Hari comments:
This doesnt work for an mxn layout where n>1.
it should be this but theres some reputation points requirement now so I cant post:
set(newh(j),'Position',[possub(1)+(posnewh(1)*possub(3)), possub(2)+(posnewh(2)*possub(4)), posnewh(3)*possub(3), posnewh(4)*possub(4)])
その他の回答 (1 件)
Eric Sargent
2020 年 12 月 9 日
Starting in R2019b, you can use tiledlayout to manage several axes. You can reparent each of your axes into a layout, and set the tile number of each axes as appropriate.
% Get a list of all of the open figures
figlist=get(groot,'Children');
newfig=figure;
tcl=tiledlayout(newfig,'flow')
for i = 1:numel(figlist)
figure(figlist(i));
ax=gca;
ax.Parent=tcl;
ax.Layout.Tile=i;
end
参考
カテゴリ
Help Center および File Exchange で Subplots についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!