Global legend for all subplots in a figure placed ON the figure (not outside the figure)?
Afficher commentaires plus anciens
Hello :)
So, I'd like to make one legend on the second subplot (the big one to the right in the figure) and it has to be one legend for all three graphs with the red one appearing first.
BUT when I try the following as shown by the code below, I can only get the legend placed above the first subplot but below the second subplot, as if the legend belongs to the first subplot, so giving the legend a new position does not solve the problem.
Any help to solve this will be appreciated, thanks :)
Best regards, Henriettte
figure
ax1 = subplot(1,2,1);
hold on
p1 = plot(time1,temp1,'.-','MarkerSize',10,'Color',Cdefault(2,:));
P1 = get(gca, 'Position');
set(gca,'Units','Normalized','Position',P1.*[1 0.7 0.45 0.7])
xlabel('Time [min]','Interpreter','latex')
ylabel('Surface temperature [$^{\circ}$C]','Interpreter','latex')
ax2 = subplot(1,2,2);
p2 = plot(time2,temp2,'.-','MarkerSize',10,'Color',[0.2 0.6 1.0]);
hold on
p3 = plot(time3,temp3,'.-','MarkerSize',10,'Color',[0.0 0.0 0.8]);
P2 = get(gca, 'Position');
set(gca,'Units','Normalized','Position',P2.*[0.55 0.7 2 0.7])
xlim([0 45])
xlabel('Time [min]','Interpreter','latex') % % %
linkaxes([ax1,ax2],'y');
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.05, 0.7, 1.0])
yticklabels(ax2,{})
t.TileSpacing = 'none';
legend([p1,p2,p3],{'Brake test on: Heating',...
'Brake test off: Natural cool down',...
'Brake test off + Cooling system on: Forced cool down',...
'Location','NorthEast'})
hold off
(specifications to 'prettyfy' the figure has been left out in the code)

Réponse acceptée
Plus de réponses (1)
randerss simil
le 13 Fév 2021
Modifié(e) : randerss simil
le 13 Fév 2021
figure
ax1 = subplot(2,1,1);
...% your code
....
xlabel('Time [min]','Interpreter','latex')
ylabel('Surface temperature [$^{\circ}$C]','Interpreter','latex')
ax2 = subplot(2,1,2);
...
Try subplot with something like above,
1 commentaire
Henriette Larsen
le 13 Fév 2021
Modifié(e) : Henriette Larsen
le 13 Fév 2021
Catégories
En savoir plus sur Title dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!