Add two figures in the one single plot

Hello all,
I do have two figures output from the matlab code (with the same axis unit) and i would like to keep both figures in the one single figure only. How can i do that ?
For example, you can refer two figures as attached
Thanks

1 commentaire

Rik
Rik le 19 Oct 2022
Is there a particular reason you're @-mentioning me? It doesn't look like you're stuck with the people already helping you in this thread.

Connectez-vous pour commenter.

Réponses (2)

Image Analyst
Image Analyst le 18 Oct 2022
Don't call figure. Call subplot instead
subplot(1, 2, 1);
plot(x1, y1);
subplot(1, 2, 2);
plot(x2, y2);

1 commentaire

Esila Darci
Esila Darci le 19 Oct 2022
Modifié(e) : Esila Darci le 19 Oct 2022
@Image Analyst, i have only saved image in mat format (I do not have x1, y1, x2 and y2). So i do not know, how to merge the two figures. Also, i am afraid that subplot will show two different plot in one figure but i need only one figure with only one x and y axis. You can see the attached merged figure 1 and 2.
Can you please tell me how to merge the figures into the one figure.
Thank you very much in advance
Esila

Connectez-vous pour commenter.

Kevin Holly
Kevin Holly le 18 Oct 2022
Modifié(e) : Kevin Holly le 18 Oct 2022
tiledlayout(2,1)
nexttile
scatter(rand(10,1),rand(10,1),'sr')
nexttile
scatter(rand(10,1),rand(10,1),'gh')
You can also use the hold function.
figure
scatter(rand(10,1),rand(10,1),'sr')
hold on
scatter(rand(10,1),rand(10,1),'gh')
If you want to merge the two figures you have into one plot:
fig1 = openfig('Figure 1.fig');
fig2 = openfig('Figure 2.fig');
for ii = length(fig1.Children.Children):-1:1
fig1.Children.Children(ii).Parent=fig2.Children;
end

5 commentaires

The techniques I used should work. Did you try it on your data? After transferring the data points from one figure to the other, you can delete the empty figure.
example = figure;
delete(example)
The figure you sent has different data from that of Figure 1 and Figure 2 that you previously sent.
fig = openfig('Merged figure 1 and 2.fig');
xlim([0.12 0.20])
ylim([-0.01 0.08])
fig1 = openfig('Figure 1.fig');
xlim([0.12 0.20])
ylim([-0.01 0.08])
fig2 = openfig('Figure 2.fig');
xlim([0.12 0.20])
ylim([-0.01 0.08])
Image Analyst
Image Analyst le 19 Oct 2022
Can you please post screenshots as PNG image files, not as .fig files. If it's a PNG file I can see it right here in the browser. If it's a .fig file I need to
  1. Right click on the fig file and say save as.
  2. Browse to some folder where I want to save it, then save it.
  3. Switch from Browser to MATLAB
  4. In MATLAB click the Open button then locate the file I saved in the browser and open it.
That's a lot more work just to see the image when I could easily see it here with no clicks or at most one click.
Image Analyst
Image Analyst le 20 Oct 2022
Modifié(e) : Image Analyst le 20 Oct 2022
OK fine, I'll do it, to help others. Here are screenshots of the .fig files:
Fig1:
FIG 2 below (looks the same as fig 1 to me)
FIG 3 below
I don't see any weird scale changes in the PNG files as compared to when I opened the .fig files. Where is the problem such that you could not post these screenshots?
But I still don't know what you want because @Kevin Holly posted both sets of data in the same plot and you said he didn't understand what you want. Please use Photoshop or something to create a mock-up of what you want your final graph to look like, and save it as a PNG file and post it.
Image Analyst
Image Analyst le 21 Oct 2022
Do you have the x and y values for each figure? You should have them before you created and save the figure. Can you post the x and y values in a .mat file?
@Esila Darci I did merge Figure 1 and Figure 2. Since both figures had the same datapoints, you cannot notice the change without looking at the figure handle.
Below you can see Figure 1 and Figure 2 are the same.
openfig('Figure 1.fig');
xlim([-0.1 0.2])
ylim([-0.04 .16])
openfig('Figure 2.fig');
xlim([-0.1 0.2])
ylim([-0.04 .16])
Now I'm going to change the colors of all the lines in Figure 2 to green.
fig = openfig('Figure 2.fig');
for ii = length(fig.Children.Children):-1:1
fig.Children.Children(ii).Color = 'g';
end
xlim([-0.1 0.2])
ylim([-0.04 .16])
This is what Figure 3 looks like
openfig('Figure 3.fig');
xlim([-0.1 0.2])
ylim([-0.04 .16])
I will now take points from Figure 2 and Figure 3 and place them on Figure 4.
fig2 = openfig('Figure 2.fig');
for ii = length(fig2.Children.Children):-1:1
fig2.Children.Children(ii).Color = 'g';
end
fig3 = openfig('Figure 3.fig');
fig4 = figure;
axes;
% Moving Figure 3 lines to Figure 4
for ii = length(fig3.Children.Children):-1:1
fig3.Children.Children(ii).Parent = fig4.Children;
end
% Moving Figure 2 lines to Figure 4
for ii = length(fig2.Children.Children):-1:1
fig2.Children.Children(ii).Parent = fig4.Children;
end
% Remove empty figures
delete(fig2)
delete(fig3)

Connectez-vous pour commenter.

Catégories

En savoir plus sur Creating, Deleting, and Querying Graphics Objects dans Centre d'aide et File Exchange

Produits

Version

R2022a

Commenté :

le 21 Oct 2022

Community Treasure Hunt

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

Start Hunting!

Translated by