One legend for a group of subtightplots
In the following plot, formed by 4 subtightplots, how can I have just one (outside) legend for the left plots, and just one right (outside) legend for the right plots?
addpath(‘/…/subtightplot’);
subplot = @(m,n,p) subtightplot (m, n, p, [0.03 0], [0.04 0.03], [0.06 0.06]);
figure(‘position’,[700 100 1200 1200],’Color’,[1 1 1]);
hold on
for i = 1 : 4
subplot(2,2,i);
if i == 1 || i == 3 %%% left plots
hold on
t = 0:1:10;
plot(t,20.*cos(t),’^–‘,’LineWidth’,1,’Color’,’b’)
plot(1:10,(1:10).^2,’^–‘,’LineWidth’,1,’Color’,’k’)
plot(1:10,(1:10).^2.3,’^–‘,’LineWidth’,1,’Color’,’g’)
hold off
else %%% right plots
hold on
plot(1:10,randi([-50,50],10,1),’o-‘,’LineWidth’,1,’Color’,’r’)
plot(1:10,randi([-50,50],10,1),’o-‘,’LineWidth’,1,’Color’,’m’)
plot(1:10,randi([-50,50],10,1),’o-‘,’LineWidth’,1,’Color’,’y’)
hold off
end
legend(‘Box’,’off’);
end
hold off
This is the my desired result:In the following plot, formed by 4 subtightplots, how can I have just one (outside) legend for the left plots, and just one right (outside) legend for the right plots?
addpath(‘/…/subtightplot’);
subplot = @(m,n,p) subtightplot (m, n, p, [0.03 0], [0.04 0.03], [0.06 0.06]);
figure(‘position’,[700 100 1200 1200],’Color’,[1 1 1]);
hold on
for i = 1 : 4
subplot(2,2,i);
if i == 1 || i == 3 %%% left plots
hold on
t = 0:1:10;
plot(t,20.*cos(t),’^–‘,’LineWidth’,1,’Color’,’b’)
plot(1:10,(1:10).^2,’^–‘,’LineWidth’,1,’Color’,’k’)
plot(1:10,(1:10).^2.3,’^–‘,’LineWidth’,1,’Color’,’g’)
hold off
else %%% right plots
hold on
plot(1:10,randi([-50,50],10,1),’o-‘,’LineWidth’,1,’Color’,’r’)
plot(1:10,randi([-50,50],10,1),’o-‘,’LineWidth’,1,’Color’,’m’)
plot(1:10,randi([-50,50],10,1),’o-‘,’LineWidth’,1,’Color’,’y’)
hold off
end
legend(‘Box’,’off’);
end
hold off
This is the my desired result: In the following plot, formed by 4 subtightplots, how can I have just one (outside) legend for the left plots, and just one right (outside) legend for the right plots?
addpath(‘/…/subtightplot’);
subplot = @(m,n,p) subtightplot (m, n, p, [0.03 0], [0.04 0.03], [0.06 0.06]);
figure(‘position’,[700 100 1200 1200],’Color’,[1 1 1]);
hold on
for i = 1 : 4
subplot(2,2,i);
if i == 1 || i == 3 %%% left plots
hold on
t = 0:1:10;
plot(t,20.*cos(t),’^–‘,’LineWidth’,1,’Color’,’b’)
plot(1:10,(1:10).^2,’^–‘,’LineWidth’,1,’Color’,’k’)
plot(1:10,(1:10).^2.3,’^–‘,’LineWidth’,1,’Color’,’g’)
hold off
else %%% right plots
hold on
plot(1:10,randi([-50,50],10,1),’o-‘,’LineWidth’,1,’Color’,’r’)
plot(1:10,randi([-50,50],10,1),’o-‘,’LineWidth’,1,’Color’,’m’)
plot(1:10,randi([-50,50],10,1),’o-‘,’LineWidth’,1,’Color’,’y’)
hold off
end
legend(‘Box’,’off’);
end
hold off
This is the my desired result: legend, subtightplot MATLAB Answers — New Questions