subplot of already saved figures
이전 댓글 표시
i have somany figures like dyke_tap, dyke_tbp,dyke_tcp and dyke_tdp...... they aare all bar plots and i want to have them side by side in other to compare them. i have seen ways of merging them, but that wont be good for what i want so i want to use a subplot. how can i use a subplot on already saved figures..... example ' having 'dyke_tap, dyke_tbp,dyke_tcp and dyke_tdp' side by side
댓글 수: 2
David Sanchez
2013년 8월 21일
what is the images extension? .fig? .png?
답변 (5개)
laurie
2013년 8월 21일
Here is a small bit of code that does just that for two saved figures. The figures need to be saved in the .fig format with this code (hgload only takes .fig figures as inputs), but there might be some way to adapt this code to make it work for other formats.
% Load saved figures
c=hgload('MyFirstFigure.fig');
k=hgload('MySecondFigure.fig');
% Prepare subplots
figure
h(1)=subplot(1,2,1);
h(2)=subplot(1,2,2);
% Paste figures on the subplots
copyobj(allchild(get(c,'CurrentAxes')),h(1));
copyobj(allchild(get(k,'CurrentAxes')),h(2));
% Add legends
l(1)=legend(h(1),'LegendForFirstFigure')
l(2)=legend(h(2),'LegendForSecondFigure')
댓글 수: 12
Iyk
2013년 8월 21일
Walter Roberson
2013년 8월 21일
Try
copyobj(allchild(c), h(1))
copyobj(allchild(k), h(2))
ismet saygu
2016년 1월 28일
편집: ismet saygu
2016년 1월 28일
After you load saved figures (like c=hgload('MyFirstFigure.fig'); k=hgload('MySecondFigure.fig');), do not close the figure window
Walter Roberson
2016년 1월 28일
You can close the figure windows once the copying is done.
Jingyun Yang
2018년 10월 4일
The legends of the fig.s are lost. Is there any way to resolve that? Thanks.
Walter Roberson
2018년 10월 5일
To take into account colorbars, annotations, legends, and some more obscure constructs, a more complete method is needed. See for example https://www.mathworks.com/matlabcentral/answers/262265-duplicating-an-imshow-image-into-a-new-figure-without-using-imshow#comment_332459
Nathaniel H Werner
2019년 2월 5일
I have a similar problem, but I am just plotting different simulation cases of the same data so I only need a single legend for all the variable I am plotting. Is there a way to get the legend to be on the 'northeastoutside' location like in a normal plot but for the entire subplot without messing with the size of any of the individual figures? I need to keep them the same scale for comparison purposes.
Wenyi Xiao
2019년 6월 11일
If my original figure are subplots, what should I do?
Walter Roberson
2019년 6월 11일
subplots are just axes.
You probably want to arrange each figure within a uipanel to frame it.
Yunyu Hu
2020년 5월 5일
This method works. But it does not copy the legend to the subplot
Walter Roberson
2020년 5월 5일
Which method were you using, Yunyu Hu? Did you follow to https://www.mathworks.com/matlabcentral/answers/262265-duplicating-an-imshow-image-into-a-new-figure-without-using-imshow#comment_332459 ?
Lehung Nguyen
2024년 5월 13일
Hello,
I used your code and it works.
In the original figure, I use semilogy. The subplot, however, display in the normal scale. How can I fix this ?
Thanks
Farhad Sedaghati
2015년 6월 22일
편집: Farhad Sedaghati
2015년 6월 22일
5 개 추천
You can use the following function to insert all the saved fig files next to each other: http://www.mathworks.com/matlabcentral/fileexchange/51236-subplot
Jesica Gomez
2017년 2월 20일
2 개 추천
Hi, does it work for 3d graphs? I'm trying to use the code but it plots 2D graphs.
Thanks
Tasos Ampelas
2018년 8월 7일
1 개 추천
Hi everyone,
In the @laurie 's first answer code, is there a way to get only the final figure and not every single one that I have loaded to matlab?
Md Modassir Firdaus
2022년 12월 30일
Hi everone,
You can try this code to create single figure having subplots. Here single plot is in subplot becouse it does not saved figure 1. First save the created plot then comment "savefig".
clc;
close all;
clear;
%%
z1=peaks;
z2=z1+randn(size(z1))/5;
figure(1)
surf(z1) %creating first figure
savefig('PeaksFile1.fig') % save the figure once then comment it
%%%%
figure(2)
surf(z2,'FaceColor','r') %creating second figure
savefig('PeaksFile2.fig')% save the figure once then comment it
%% Loading saved above figure
f1=hgload('PeaksFile1.fig');
f2=hgload('PeaksFile2.fig');
%% creating subplot
figure(3)
h(1)=subplot(1,2,1);
view(3)
grid on
h(2)=subplot(1,2,2);
view(3)
grid on
%%
copyobj(allchild(get(f1,'CurrentAxes')),h(1));
copyobj(allchild(get(f2,'CurrentAxes')),h(2));
카테고리
도움말 센터 및 File Exchange에서 Subplots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!