범례 속성

범례 속성 (Legend Properties)

범례(legend)는 그래프의 각 항목이 무엇을 뜻하는지 알려주는 핵심 요소예요. 이 문서에서는 legend 객체가 갖는 속성을 항목별로 정리해요. 범례의 위치, 색, 글꼴, 항목 배치, 클릭 콜백 같은 요소를 이 속성들로 제어할 수 있어요.

출처: 문서

본문

legend 객체(see legend)의 속성은 크게 콜백 실행(Callback Execution), 배치(Layout), 범례 외형(Legend Appearance), 객체 식별(Object Identification), 객체 위치(Object Position), 텍스트 외형(Text Appearance) 여섯 범주로 나뉘어요.

콜백 실행 (Callback Execution)

itemhitfcn: 기본 [](0x0)

범례 항목을 클릭했을 때 실행되는 콜백 함수예요. Callbacks 섹션을 참고하세요. 콜백 함수는 fcn (hlegend, evnt) 형태의 프로토타입을 가져야 해요. 여기서 hlegend는 범례 객체 핸들이고, evnt는 다음 필드를 가진 구조체예요.

  • Peer — 클릭한 항목과 연결된 플롯 객체의 핸들.
  • Region — 항목의 어느 부분을 클릭했는지에 따라 "icon" 또는 "label".
  • SelectionType"normal", "extend", "open", "alt" 중 하나. Figure의 "selectiontype" 참고.
  • Source — 범례 객체의 핸들.
  • EventName — 이름은 "ItemHit".

배치 (Layout)

autoupdate: "off" | {"on"}

피어 axes에 객체가 추가(또는 삭제)될 때 범례 항목 수를 자동으로 갱신할지 제어해요. 예를 들어 보죠.

## Create a single plot with its legend.
figure ();
plot (1:10);
legend ("Slope 1");
## Add another plot and specify its displayname so that
## the legend is correctly updated.
hold on;
plot ((1:10) * 2, "displayname", "Slope 2");
## Stop automatic updates for further plots.
legend ("autoupdate", "off");
plot ((1:10) * 3);

numcolumns: 스칼라 정수, 기본 1

범례 항목 배치에 사용할 열 수를 제어해요. 예를 들어 보죠.

figure ();
plot (rand (30));
legend ("numcolumns", 3);

numcolumns를 설정하면 numcolumnsmode 속성도 "manual"로 강제 설정돼요.

orientation: "horizontal" | {"vertical"}

범례 항목을 세로(열 방향)로 배열할지 가로(행 방향)로 배열할지 제어해요.

범례 외형 (Legend Appearance)

box: "off" | {"on"}

범례에 둘러싸는 테두리 상자를 그릴지 제어해요.

color: colorspec, 기본 [1 1 1]

범례 배경의 색이에요. colorspec 참고.

edgecolor: colorspec, 기본 [0.1500 0.1500 0.1500]

범례 윤곽선의 색을 제어해요.

객체 식별 (Object Identification)

title: 그래픽스 핸들

제목 텍스트 객체의 그래픽스 핸들이에요.

객체 위치 (Object Position)

location: "best" | "bestoutside" | "east" | "eastoutside" | "none" | "north" | {"northeast"} | "northeastoutside" | "northoutside" | "northwest" | "northwestoutside" | "south" | "southeast" | "southeastoutside" | "southoutside" | "southwest" | "southwestoutside" | "west" | "westoutside"

범례의 위치를 제어해요.

position: 네 원소 벡터

제목을 제외한 범례의 위치를 지정해요. 벡터의 네 원소는 범례의 왼쪽 아래 모서리 좌표와 너비, 높이예요. 이 속성을 바꾸면 "location""none"으로 전환돼요.

units: "centimeters" | "characters" | "inches" | {"normalized"} | "pixels" | "points"

"position" 속성을 해석하는 데 쓰는 단위예요.

텍스트 외형 (Text Appearance)

fontangle: "italic" | {"normal"}

글꼴을 이탤릭으로 할지 보통으로 할지 제어해요.

fontname: 문자열, 기본 "*"

텍스트 렌더링에 쓰는 글꼴 이름이에요. 이 속성을 설정하면 텍스트 렌더링 엔진이 시스템에서 일치하는 글꼴을 찾아요. 찾지 못하면 기본 산세리프(sans serif) 글꼴(기본값 "*"와 동일)로 렌더링해요. 프로그래밍 참고: FontConfig를 기본으로 쓰지 않는 시스템(Linux를 제외한 대부분)에서는 Octave 설치 시 글꼴 캐시가 만들어져요. 새 글꼴을 설치한 뒤에는 system ("fc-cache -fv")를 직접 실행해야 해요.

fontsize: 스칼라, 기본 9

텍스트 렌더링에 쓰는 글꼴 크기예요. fontunits 속성 참고. fontsize를 설정하면 fontsizemode 속성도 "manual"로 강제 설정돼요.

fontunits: "centimeters" | "inches" | "normalized" | "pixels" | {"points"}

"fontsize" 속성을 해석하는 데 쓰는 단위예요.

fontweight: "bold" | {"normal"}

텍스트 렌더링에 쓰는 기본 글꼴의 변형을 제어해요.

string: 문자열 | 문자열 셀 배열

범례 항목의 라벨 목록이에요. 예를 들어 보죠.

figure ();
plot (rand (20));
## Let legend choose names automatically
hl = legend ();
## Selectively change some names
str = get (hl, "string");
str(1:5:end) = "Garbage";
set (hl, "string", str);

textcolor: colorspec, 기본 [0 0 0]

범례 항목의 텍스트 문자열 색을 제어해요.

더 알아보기

  • 범례를 만드는 legend 함수 자체를 함께 살펴보세요.
  • 그래픽 객체 속성을 읽고 쓰는 get·set 함수와 Callbacks 섹션도 이어서 확인해 보세요.