Main Content

컬러맵을 사용하여 색 체계 변경하기

MATLAB®은 곡면 플롯 같은 시각화를 표시할 때 디폴트 색 체계를 사용합니다. 컬러맵을 지정하여 색 체계를 변경할 수 있습니다. 컬러맵은 RGB 3색을 포함한 3열 배열로, 각 행은 각기 다른 색을 정의합니다.

예를 들어, 다음은 디폴트 색 체계가 적용된 곡면 플롯입니다.

f = figure;
surf(peaks);

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

다음 명령은 현재 Figure의 컬러맵을 미리 정의된 여러 개의 컬러맵 중 하나인 winter로 변경합니다(전체 목록은 컬러맵 참조).

colormap winter;

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

여러 Figure가 열려 있는 경우에는 Figure 객체를 colormap 함수에 대한 첫 번째 인수로서 전달합니다.

colormap(f,hot);

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

미리 정의된 각 컬러맵은 기본적으로 256색 팔레트를 제공합니다. 그러나, 정수를 미리 정의된 컬러맵 함수로 전달하여 색 개수를 원하는 대로 지정할 수 있습니다. 예를 들어, 다음은 10개 항목이 포함된 hot 컬러맵입니다.

c = hot(10);
colormap(c);

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

m×3 배열로 자신만의 고유한 컬러맵을 생성할 수도 있습니다. 배열의 각 행에는 다양한 색의 빨간색, 녹색, 파란색 농도가 포함되어 있습니다. 농도의 범위는 [0,1]입니다. 다음은 3개 항목이 포함된 단순한 컬러맵입니다.

mycolors = [1 0 0; 1 1 0; 0 0 1];
colormap(mycolors);

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

여러 좌표축을 사용하여 작업 중인 경우, axes 객체를 colormap 함수로 전달하여 각 좌표축에 각기 다른 컬러맵을 할당할 수 있습니다.

tiledlayout(1,2)
ax1 = nexttile;
surf(peaks);
shading interp;
colormap(ax1,parula(10));

ax2 = nexttile;
surf(peaks);
shading interp;
colormap(ax2,cool(10));

Figure contains 2 axes objects. Axes object 1 contains an object of type surface. Axes object 2 contains an object of type surface.

관련 항목