two legends in the same box

2 次查看(过去 30 天)
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])

采纳的回答

Adam Danz
Adam Danz 2021-4-6
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 个评论
Adam Danz
Adam Danz 2021-4-7
编辑:Adam Danz 2021-4-7
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).

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Axes Appearance 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by