How to combine two figures into one figure?

3 vues (au cours des 30 derniers jours)
Chao-Zhen Liu
Chao-Zhen Liu le 25 Fév 2019
Commenté : Chao-Zhen Liu le 25 Fév 2019
Hi,
I have two figures which each one is a 1x3 subplot now and I want to combine these two figures into one figure for some use.
Originally, i want to use a 2x3 subplot to present the result but the 2x3 subplot will make the fugure trend is not so clear (each subplot is to flat).
Finally, I break up the 2x3 subplot into two 1x3 subplots and get the clear figure trend.
However, since these two 1x3 subplots are under the same topic and I want to combine it into one figure that keeps the clear figure trend but could not achieve this goal.
Does anyone can tell me how to handle it?
Below is my code:
clc; clear
a = xlsread('just test' , 'linechart', 'C5:J154');
b = xlsread('just test' , 'linechart', 'N5:U154');
c = xlsread('just test' , 'linechart', 'Y5:AF154');
for i = 1:1:25
% BCPB_Ratio
x1(i,1) = a(( i-1)*6+1,1); y1(i,1) = b(( i-1)*6+1,1); z1(i,1) = c(( i-1)*6+1,1); %n = 30
x2(i,1) = a(( i-1)*6+2,1); y2(i,1) = b(( i-1)*6+2,1); z2(i,1) = c(( i-1)*6+2,1); %n = 40
x3(i,1) = a(( i-1)*6+3,1); y3(i,1) = b(( i-1)*6+3,1); z3(i,1) = c(( i-1)*6+3,1);
x4(i,1) = a(( i-1)*6+4,1); y4(i,1) = b(( i-1)*6+4,1); z4(i,1) = c(( i-1)*6+4,1);
x5(i,1) = a(( i-1)*6+5,1); y5(i,1) = b(( i-1)*6+5,1); z5(i,1) = c(( i-1)*6+5,1);
x6(i,1) = a(( i-1)*6+6,1); y6(i,1) = b(( i-1)*6+6,1); z6(i,1) = c(( i-1)*6+6,1);
% BCPB_Diff
x7(i,1) = a(( i-1)*6+1,2); %n = 30
x8(i,1) = a(( i-1)*6+2,2);
x9(i,1) = a(( i-1)*6+3,2);
x10(i,1) = a(( i-1)*6+4,2);
x11(i,1) = a(( i-1)*6+5,2);
x12(i,1) = a(( i-1)*6+6,2);
% GCI_Ratio
x13(i,1) = a(( i-1)*6+1,3); y13(i,1) = b(( i-1)*6+1,3); z13(i,1) = c(( i-1)*6+1,3); %n = 30
x14(i,1) = a(( i-1)*6+2,3); y14(i,1) = b(( i-1)*6+2,3); z14(i,1) = c(( i-1)*6+2,3);
x15(i,1) = a(( i-1)*6+3,3); y15(i,1) = b(( i-1)*6+3,3); z15(i,1) = c(( i-1)*6+3,3);
x16(i,1) = a(( i-1)*6+4,3); y16(i,1) = b(( i-1)*6+4,3); z16(i,1) = c(( i-1)*6+4,3);
x17(i,1) = a(( i-1)*6+5,3); y17(i,1) = b(( i-1)*6+5,3); z17(i,1) = c(( i-1)*6+5,3);
x18(i,1) = a(( i-1)*6+6,3); y18(i,1) = b(( i-1)*6+6,3); z18(i,1) = c(( i-1)*6+6,3);
% GCI_Diff
x19(i,1) = a(( i-1)*6+1,4); %n = 30
x20(i,1) = a(( i-1)*6+2,4);
x21(i,1) = a(( i-1)*6+3,4);
x22(i,1) = a(( i-1)*6+4,4);
x23(i,1) = a(( i-1)*6+5,4);
x24(i,1) = a(( i-1)*6+6,4);
% MC(G)_Ratio
x25(i,1) = a(( i-1)*6+1,5); %n = 30
x26(i,1) = a(( i-1)*6+2,5);
x27(i,1) = a(( i-1)*6+3,5);
x28(i,1) = a(( i-1)*6+4,5);
x29(i,1) = a(( i-1)*6+5,5);
x30(i,1) = a(( i-1)*6+6,5);
% MC(G)_Diff
x31(i,1) = a(( i-1)*6+1,6); %n = 30
x32(i,1) = a(( i-1)*6+2,6);
x33(i,1) = a(( i-1)*6+3,6);
x34(i,1) = a(( i-1)*6+4,6);
x35(i,1) = a(( i-1)*6+5,6);
x36(i,1) = a(( i-1)*6+6,6);
% MC(A)_Ratio
x37(i,1) = a(( i-1)*6+1,7); y37(i,1) = b(( i-1)*6+1,7); z37(i,1) = c(( i-1)*6+1,7); %n = 30
x38(i,1) = a(( i-1)*6+2,7); y38(i,1) = b(( i-1)*6+2,7); z38(i,1) = c(( i-1)*6+2,7);
x39(i,1) = a(( i-1)*6+3,7); y39(i,1) = b(( i-1)*6+3,7); z39(i,1) = c(( i-1)*6+3,7);
x40(i,1) = a(( i-1)*6+4,7); y40(i,1) = b(( i-1)*6+4,7); z40(i,1) = c(( i-1)*6+4,7);
x41(i,1) = a(( i-1)*6+5,7); y41(i,1) = b(( i-1)*6+5,7); z41(i,1) = c(( i-1)*6+5,7);
x42(i,1) = a(( i-1)*6+6,7); y42(i,1) = b(( i-1)*6+6,7); z42(i,1) = c(( i-1)*6+6,7);
% MC(A)_Diff
x43(i,1) = a(( i-1)*6+1,8); %n = 30
x44(i,1) = a(( i-1)*6+2,8);
x45(i,1) = a(( i-1)*6+3,8);
x46(i,1) = a(( i-1)*6+4,8);
x47(i,1) = a(( i-1)*6+5,8);
x48(i,1) = a(( i-1)*6+6,8);
end
x=1:1:25;
f1 = figure; f2 = figure;
p1 = uipanel('Parent',f1,'BorderType','none'); p2 = uipanel('Parent',f2,'BorderType','none');
p1.Title = 'BCPB(R) with smaller n'; p2.Title = 'ARMS(R) with smaller n';
p1.TitlePosition = 'centertop'; p2.TitlePosition = 'centertop';
p1.FontSize = 30; p2.FontSize = 30;
p1.FontWeight = 'bold'; p2.FontWeight = 'bold';
%========================The first 1x3 subplot===========================
figure(f1);
subplot(1,3,1,'Parent',p1)
plot(x,x1,'.--',x,x2 ,'.:',x,x3,'.-', 'LineWidth',2.5,'MarkerSize',30);
title('Du/Dl = 1/1','fontsize',25);
axis([-inf inf 0.8400 0.9500]);
line([1 25],[0.9173 0.9173],'LineWidth',3.5,'Color', [0.7 0.7 0.7])
line([1 25],[0.9000 0.9000],'LineWidth',1.5,'LineStyle','--','Color', [0.7 0.7 0.7])
line([1 25],[0.8827 0.8827],'LineWidth',3.5,'Color', [0.7 0.7 0.7])
legend('n = 30','n = 40','n = 50','Location','northwest');
set(gca,'fontsize',20);
xlabel('Design','fontsize',30); ylabel('Coverage rate','fontsize',30);
subplot(1,3,2,'Parent',p1)
plot(x,y1,'.--',x,y2 ,'.:',x,y3,'.-', 'LineWidth',2.5,'MarkerSize',30);
title('Du/Dl = 1/2','fontsize',25);
axis([-inf inf 0.8400 0.9500]);
line([1 25],[0.9173 0.9173],'LineWidth',3.5,'Color', [0.7 0.7 0.7])
line([1 25],[0.9000 0.9000],'LineWidth',1.5,'LineStyle','--','Color', [0.7 0.7 0.7])
line([1 25],[0.8827 0.8827],'LineWidth',3.5,'Color', [0.7 0.7 0.7])
legend('n = 30','n = 40','n = 50','Location','northwest');
set(gca,'fontsize',20);
xlabel('Design','fontsize',30); ylabel('Coverage rate','fontsize',30);
subplot(1,3,3,'Parent',p1)
plot(x,z1,'.--',x,z2 ,'.:',x,z3,'.-', 'LineWidth',2.5,'MarkerSize',30);
title('Du/Dl = 1/3','fontsize',25);
axis([-inf inf 0.8400 0.9500]);
line([1 25],[0.9173 0.9173],'LineWidth',3.5,'Color', [0.7 0.7 0.7])
line([1 25],[0.9000 0.9000],'LineWidth',1.5,'LineStyle','--','Color', [0.7 0.7 0.7])
line([1 25],[0.8827 0.8827],'LineWidth',3.5,'Color', [0.7 0.7 0.7])
legend('n = 30','n = 40','n = 50','Location','northwest');
set(gca,'fontsize',20);
xlabel('Design','fontsize',30); ylabel('Coverage rate','fontsize',30);
%========================The second 1x3 subplot===========================
figure(f2);
subplot(1,3,1,'Parent',p2)
plot(x,x37,'.--',x,x38 ,'.:',x,x39,'.-', 'LineWidth',2.5,'MarkerSize',30);
title('Du/Dl = 1/1','fontsize',25);
axis([-inf inf 0.8400 0.9500]);
line([1 25],[0.9173 0.9173],'LineWidth',3.5,'Color', [0.7 0.7 0.7])
line([1 25],[0.9000 0.9000],'LineWidth',1.5,'LineStyle','--','Color', [0.7 0.7 0.7])
line([1 25],[0.8827 0.8827],'LineWidth',3.5,'Color', [0.7 0.7 0.7])
legend('n = 30','n = 40','n = 50','Location','northwest');
xlabel('Design','fontsize',30); ylabel('Coverage rate','fontsize',30);
set(gca,'fontsize',20);
subplot(1,3,2,'Parent',p2)
plot(x,y37,'.--',x,y38 ,'.:',x,y39,'.-', 'LineWidth',2.5,'MarkerSize',30);
title('Du/Dl = 1/2','fontsize',25);
axis([-inf inf 0.8400 0.9500]);
line([1 25],[0.9173 0.9173],'LineWidth',3.5,'Color', [0.7 0.7 0.7])
line([1 25],[0.9000 0.9000],'LineWidth',1.5,'LineStyle','--','Color', [0.7 0.7 0.7])
line([1 25],[0.8827 0.8827],'LineWidth',3.5,'Color', [0.7 0.7 0.7])
legend('n = 30','n = 40','n = 50','Location','northwest');
xlabel('Design','fontsize',30); ylabel('Coverage rate','fontsize',30);
set(gca,'fontsize',20);
subplot(1,3,3,'Parent',p2)
plot(x,z37,'.--',x,z38 ,'.:',x,z39,'.-', 'LineWidth',2.5,'MarkerSize',30);
title('Du/Dl = 1/3','fontsize',25);
axis([-inf inf 0.8400 0.9500]);
line([1 25],[0.9173 0.9173],'LineWidth',3.5,'Color', [0.7 0.7 0.7])
line([1 25],[0.9000 0.9000],'LineWidth',1.5,'LineStyle','--','Color', [0.7 0.7 0.7])
line([1 25],[0.8827 0.8827],'LineWidth',3.5,'Color', [0.7 0.7 0.7])
legend('n = 30','n = 40','n = 50','Location','northwest');
xlabel('Design','fontsize',30); ylabel('Coverage rate','fontsize',30);
set(gca,'fontsize',20);
Two 1x3 subplot are like below:
1st.jpg
2nd.jpg
Now I want to keep its shape and combine these two 1x3 subplot into one figure. How can I do it?
Any help would be much appreciated. Thanks

Réponse acceptée

Walter Roberson
Walter Roberson le 25 Fév 2019
Modifié(e) : Walter Roberson le 25 Fév 2019
subplot(2,6,n) instead of subplot(2,3,n), using subplot numbers 1, 2, 3 for the first plot, and 7, 8, 9 for the second plot, and not plotting the others.
You are happy with a 1:1/3 aspect ratio . When you have to go to 1/2 height to get two rows in, the to keep the aspect ratio that would be 1/2:1/6 , leading to subplot(2,6,*)
  3 commentaires
Walter Roberson
Walter Roberson le 25 Fév 2019
Without changing the aspect ratio, all you could do is move the subplots further apart from each other.
You could experiment with (2,5,*) plots 1, 2, 3, 6, 7, 8, or with (2,4,*) plots 1, 2, 3, 5, 6, 7 to see if those are acceptable.
Chao-Zhen Liu
Chao-Zhen Liu le 25 Fév 2019
Hi Walter,
Oh, thanks, I will try it after a while.
Much appreciated!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by