two legends in the same box

조회 수: 2 (최근 30일)
Babu Sankhi
Babu Sankhi 2021년 4월 6일
편집: Adam Danz 2021년 4월 7일
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
Babu Sankhi
Babu Sankhi 2021년 4월 7일
편집: Babu Sankhi 2021년 4월 7일
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