필터 지우기
필터 지우기

Does anybody know how to include a legend in a figure of three functions with different colours or patterns?

조회 수: 2 (최근 30일)
Hi, I am plotting three functions at the same time in order to compare them and I would like to include a legend in this graphic, to represent the color and correspondet name of each function. Does anybody know how to do it?
plot(t,x1,'r'); hold on; plot(t,x2,b--o'); hold on plot(t,x3,g--');
Thank you!!!
title('Comparison'); xlabel('Time'); ylabel('f(t)');
subplot(132); plot(t1,x_rec_vel(:,2),'r'); hold on; plot(t1,Y(1:end-1,5),'b--o'); title('Velocity Mass 2'); xlabel('Time'); ylabel('v(t)');
subplot(133); plot(t1,x_rec_vel(:,3),'r'); hold on; plot(t1,Y(1:end-1,6),'b--o'); title('Velocity Mass 3'); xlabel('Time'); ylabel('v(t)');

채택된 답변

emehmetcik
emehmetcik 2015년 2월 18일
doc legend
plot(t,x1,'r');
hold on; % One 'hold on' is enough
plot(t,x2,b--o');
plot(t,x3,g--');
legend('Function-1', 'Function-2', 'Function-3')
... same for other figures as well.
You can use this form as well:
h1(1) = plot(t,x1,'r', 'displayName', 'Function-1');
hold on; % One 'hold on' is enough
h(2) = plot(t,x2,b--o', 'displayName', 'Function-1');
h(3) = plot(t,x3,g--', 'displayName', 'Function-1');
legend(h)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Legend에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by