15.3.3.4 图例属性

legend(图例)对象的属性(参见 legend):

类别:

回调执行 | 布局 | 图例外观 | 对象标识 | 对象位置 | 文本外观

回调执行

itemhitfcn: 默认值 [](0x0)

当点击图例项时执行的回调函数。参见 回调章节

回调函数必须具有以下原型:fcn (hlegend, evnt),其中 hlegend 是图例对象的句柄,evnt 是一个包含以下字段的结构体:

Peer

与点击项关联的绘图对象的句柄。

Region

可能为 "icon""label",具体取决于点击了项的哪个部分。

SelectionType

值为以下之一:"normal""extend""open""alt"。参见 图形对象 "selectiontype"

Source

图例对象的句柄。

EventName

名称为 "ItemHit"

布局

autoupdate: "off" | {"on"}

控制当对象添加到关联坐标轴(或从关联坐标轴删除)时,是否自动更新图例项的数量。 例如:

## 创建一个绘图及其图例
figure ();
plot (1:10);
legend ("Slope 1");
## 添加另一个绘图并指定其 displayname,
## 以便图例正确更新。
hold on;
plot ((1:10) * 2, "displayname", "Slope 2");
## 停止后续绘图的自动更新。
legend ("autoupdate", "off");
plot ((1:10) * 3);
numcolumns: 标量整数, 默认值 1

控制图例项布局中使用的列数。例如:

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

设置 numcolumns 也会强制将 numcolumnsmode 属性设置为 "manual"

orientation: "horizontal" | {"vertical"}

控制图例项是垂直排列(按列排列)还是水平排列(按行排列)。

图例外观

box: "off" | {"on"}

控制图例是否显示外边框。

color: 颜色规格, 默认值 [1 1 1]

图例背景的颜色。参见 颜色规格

edgecolor: 颜色规格, 默认值 [0.1500 0.1500 0.1500]

控制图例轮廓线的颜色。

对象标识

title: 图形句柄

标题文本对象的图形句柄。

对象位置

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" 属性的单位。

文本外观

fontangle: "italic" | {"normal"}

控制字体为斜体还是常规体。

fontname: 字符串, 默认值 "*"

用于文本渲染的字体名称。设置此属性时,文本渲染引擎会在系统中搜索匹配的字体。如果未找到,则使用默认的无衬线字体(与默认的 "*" 值相同)。

编程说明:在不原生使用 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));
## 让图例自动选择名称
hl = legend ();
## 选择性修改部分名称
str = get (hl, "string");
str(1:5:end) = "Garbage";
set (hl, "string", str);
textcolor: 颜色规格, 默认值 [0 0 0]

控制图例项文本的颜色。


版权所有 © 2024-2026 Octave中文网

ICP备案/许可证号:黑ICP备2024030411号-4