How to superimpose plots from 2 (.fig) files?
21 views (last 30 days)
Show older comments
Francis Lopez
on 1 Nov 2017
Commented: Francis Lopez
on 2 Nov 2017
My objective is to superimpose 2 plots from 2 (.fig) files.
One of the (.fig) that 2 plots (say, two.fig). The .fig files came from scopeData. I figured I could live only with .fig. When I tried to superimpose it with the other (.fig) (say one.fig) with only one plot, MATLAB is using the bottom plot two.fig. How can I get the top plot from two.fig to superimpose with one.fig?
Pictures included. (I'm working with (.fig) files, jpegs are just to show what I have)
I tried: x = openfig('one.fig', 'reuse'); ax1 = gca; y = openfig('two.fig','reuse'); ax2 = gca;
h3 = figure;
s1 = subplot(1,1,1);
fig1 = get(ax1, 'children'); fig2 = get(ax2, 'children');
copyobj(fig1,s1); hold on copyobj(fig2,s1); hold off
0 Comments
Accepted Answer
Cam Salzberger
on 1 Nov 2017
Edited: Cam Salzberger
on 1 Nov 2017
Hello Francis,
You were on the right track, but you only made one subplot. I'm assuming, since you're using subplot, that you want two separate axes on the figure. Here's a quick example of how you can do it with copyobj:
% Setup the figures
hFig1 = figure;
plot(1:10)
hold on
plot(2:20)
hFig2 = figure;
plot(10:-1:1)
hold on
plot(1:10)
% Create new figure and copy over
hFigTarget = figure;
hAxTar1 = subplot(2, 1, 1, 'Parent', hFigTarget);
hAxTar2 = subplot(2, 1, 2, 'Parent', hFigTarget);
hAx1 = hFig1.Children; % Assuming there's just one child
hAx2 = hFig2.Children;
copyobj(hAx1.Children, hAxTar1)
copyobj(hAx2.Children, hAxTar2)
Another way to do it would be to just copy over both axes, and change their 'Position' or 'OuterPosition' properties to simulate what subplot does. I personally find that this works pretty well to simulate subplots:
hAx1.Units = 'normalized';
hAx1.OuterPosition = [0 0.5 1 0.5];
hAx2.Units = 'normalized';
hAx2.OuterPosition = [0 0 1 0.5];
-Cam
More Answers (0)
See Also
Categories
Find more on Creating, Deleting, and Querying Graphics Objects 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!