일반적인 2차원 플롯 생성하기
이 예제에서는 MATLAB®에서 다양한 2차원 플롯을 생성하는 방법을 보여줍니다.
선 플롯
plot
함수는 x 값과 y 값으로 구성된 단순한 선 플롯을 만듭니다.
x = 0:0.05:5; y = sin(x.^2); figure plot(x,y)
선 플롯은 x, y 데이터 세트를 여러 개 표시할 수 있습니다.
y1 = sin(x.^2); y2 = cos(x.^2); plot(x,y1,x,y2)
막대 플롯
bar
함수는 세로 막대 차트를 만듭니다. barh
함수는 가로 막대 차트를 만듭니다.
x = -2.9:0.2:2.9; y = exp(-x.*x); bar(x,y)
계단 플롯
stairs
함수는 계단 플롯을 만듭니다. Y 값으로만 구성된 계단 플롯을 만들거나 x, y 값으로 구성된 계단 플롯을 만들 수 있습니다.
x = 0:0.25:10; y = sin(x); stairs(x,y)
오차 막대 플롯
errorbar
함수는 x, y 값의 선 플롯을 그린 다음 각 관측값 위에 세로 오차 막대를 겹쳐 놓습니다. 오차 막대의 크기를 지정하려면 추가 입력 인수를 errorbar
함수로 전달하십시오.
x = -2:0.1:2; y = erf(x); eb = rand(size(x))/7; errorbar(x,y,eb)
극좌표 플롯
polarplot
함수는 각도 값(단위: 라디안) theta
대 반지름 값 rho
의 극좌표 플롯을 그립니다.
theta = 0:0.01:2*pi; rho = abs(sin(2*theta).*cos(2*theta)); polarplot(theta,rho)
줄기 플롯
stem
함수는 공통 기준선에 세로선을 연결해 x, y 값에 대한 마커를 그립니다.
x = 0:0.1:4; y = sin(x.^2).*exp(-x); stem(x,y)
산점도 플롯
scatter
함수는 x, y 값의 산점도 플롯을 그립니다.
load patients Height Weight Systolic scatter(Height,Weight) xlabel('Height') ylabel('Weight')
scatter
함수에 선택적 인수를 사용하여 마커 크기와 색을 지정할 수 있습니다. 현재 좌표축에 색조를 표시하려면 colorbar
함수를 사용하십시오.
scatter(Height,Weight,20,Systolic) xlabel('Height') ylabel('Weight') colorbar