Main Content

선 플롯과 줄기 플롯 결합하기

이 예제에서는 하나의 선 플롯과 두 개의 줄기 플롯을 결합하는 방법을 보여줍니다. 그런 다음 제목, 축 레이블, 범례를 추가하는 방법을 보여줍니다.

데이터를 생성하고 선을 플로팅합니다.

x = linspace(0,2*pi,60);
a = sin(x);
b = cos(x);
plot(x,a+b)

Figure contains an axes object. The axes object contains an object of type line.

좌표축에 두 개의 줄기 플롯을 추가합니다. hold on을 사용하여 새 플롯이 기존 플롯을 대체하지 않도록 합니다.

hold on
stem(x,a)
stem(x,b)
hold off

Figure contains an axes object. The axes object contains 3 objects of type line, stem.

제목, 축 레이블, 범례를 추가합니다. 플롯이 생성되는 순서대로 범례 설명을 지정합니다.

title('Linear Combination of Two Functions')
xlabel('Time in \musecs')
ylabel('Magnitude')
legend('a+b','a = sin(x)','b = cos(x)')

Figure contains an axes object. The axes object with title Linear Combination of Two Functions, xlabel Time in mu secs, ylabel Magnitude contains 3 objects of type line, stem. These objects represent a+b, a = sin(x), b = cos(x).

참고 항목

| |