two legends in the same box
조회 수: 5(최근 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])
댓글 수: 0
채택된 답변
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
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개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!