two legends in the same box

2 visualizaciones (últimos 30 días)
Babu Sankhi
Babu Sankhi el 6 de Abr. de 2021
Editada: Adam Danz el 7 de Abr. de 2021
Hello,
I want the legends which belong to two y axes in the same box but it only displays one set of legend belonging to only one (red) y axes . Can you help me more ? I want blue ones on the right.
thank you
fig=figure(15);
left_color = [1 0 0];
right_color = [0 0 1];
set(fig,'defaultAxesColorOrder',[left_color; right_color]);
yyaxis left
plot (Ms(1:4,3),Ms(1:4,4)*1000,'ro');hold on
plot (Ms(5,3),Ms(5,4)*1000,'r*')
plot (Ms(6,3),Ms(6,4)*1000,'rs')
plot (Ms(7:8,3),Ms(7:8,4)*1000,'rd')
legend('2 s','2 io','2o','2lo')
xlabel('An (hr)')
ylabel('M (A)')
yyaxis 'right'
plot (Ms(1:4,3),Ms(1:4,5)/1000,'bo')
plot (Ms(5,3),Ms(5,5)/1000,'b*')
plot (Ms(6,3),Ms(6,5)/1000,'bs')
plot (Ms(7:8,3),Ms(7:8,5)/1000,'bd');hold off
legend('2 s','2 io','2o','2lo')
ylabel('µ(T)')
xlim([0.5 4.5])
set(gca,'FontSize',18)
set(gcf,'Position',[100 100 600 500])

Respuesta aceptada

Adam Danz
Adam Danz el 6 de Abr. de 2021
Ms = randi(10,10,10);
fig=figure(15);
left_color = [1 0 0];
right_color = [0 0 1];
set(fig,'defaultAxesColorOrder',[left_color; right_color]);
yyaxis left
plot (Ms(1:4,3),Ms(1:4,4)*1000,'ro','DisplayName', '2 s');
hold on
plot (Ms(5,3),Ms(5,4)*1000,'r*', 'DisplayName', '2 io')
plot (Ms(6,3),Ms(6,4)*1000,'rs', 'DisplayName', '2o')
plot (Ms(7:8,3),Ms(7:8,4)*1000,'rd', 'DisplayName', '2lo')
% legend('2 s','2 io','2o','2lo')
xlabel('An (hr)')
ylabel('M (A)')
yyaxis 'right'
plot (Ms(1:4,3),Ms(1:4,5)/1000,'bo','DisplayName', '2 s');
plot (Ms(5,3),Ms(5,5)/1000,'b*', 'DisplayName', '2 io')
plot (Ms(6,3),Ms(6,5)/1000,'bs', 'DisplayName', '2o')
plot (Ms(7:8,3),Ms(7:8,5)/1000,'bd', 'DisplayName', '2lo');
hold off
% legend('2 s','2 io','2o','2lo')
ylabel('µ(T)')
xlim([0.5 4.5])
set(gca,'FontSize',18)
set(gcf,'Position',[100 100 600 500])
legend('NumColumns',2)
  5 comentarios
Babu Sankhi
Babu Sankhi el 7 de Abr. de 2021
Editada: Babu Sankhi el 7 de Abr. de 2021
Adam Danz
Adam Danz el 7 de Abr. de 2021
Editada: Adam Danz el 7 de Abr. de 2021
You need to change the fontsize of the legend but this will affect the fontsize of all strings in the legend.
legend(___,'FontSize', __)
I don't know whether it's possible to specify the fontsize of single legend strings. There certainly is not a documented approach for that. When it comes to this level of detail, I usually assign labels in programs outside of Matlab (ie, powerpoint).

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Axes Appearance en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by