AnnotationValue[obj,key]
给出与对象 obj 的 key 关联的注释值.
AnnotationValue[{obj,itemspec},key]
给出与 obj 中由 itemspec 指定的项的 key 相关联的注释值.
AnnotationValue
AnnotationValue[obj,key]
给出与对象 obj 的 key 关联的注释值.
AnnotationValue[{obj,itemspec},key]
给出与 obj 中由 itemspec 指定的项的 key 相关联的注释值.
更多信息
- 通常用于提取和操作与对象或对象中的项关联的注释中的值.
- AnnotationValue 给出对象及其项的 key->value 注释中的值 value.
- 带有可注释项的可能对象:
-
Audio 时间点和时间间隔 BoundaryMeshRegion 网格单元 CSGRegion 几何区域 Graph 顶点和边 MeshRegion 网格单元 - 每种对象类型的项规范 itemspec 在其参考页面给出.
- 当找不到在 AnnotationValue 中请求的名称时,返回 Missing.
- 对于无值的标记 key,AnnotationValue[{obj,itemspec},key] 以不计算的形式返回.
- AnnotationValue[…,key]=val 可用于修改注释值.
范例
打开所有单元 关闭所有单元基本范例 (3)
g = CompleteGraph[4, VertexLabels -> {1 -> "one"}]AnnotationValue[g, VertexLabels]AnnotationValue[{g, 1}, VertexLabels] = "two";gAnnotationValue[{g, 1}, VertexLabels]=.;g获取网格中单元的固有 MeshCellMeasure 注释:
mr = MengerMesh[2]AnnotationValue[{mr, {2, 1}}, MeshCellMeasure]自动计算 Audio 对象的注释:
a = AudioAnnotate[Import["ExampleData/rule30.wav"], "Loud"];AnnotationValue[a, "Loud"]范围 (18)
图和网络 (13)
图和网络 (7)
g = CompleteGraph[4, VertexStyle -> {1 -> Blue}, VertexLabels -> {1 -> "one"}, EdgeStyle -> {12 -> Blue}, EdgeLabels -> {12 -> "hello"}]AnnotationValue[{g, 1}, {VertexStyle, VertexLabels}]AnnotationValue[{g, 12}, {EdgeStyle, EdgeLabels}]AnnotationValue[{g, 24}, {EdgeStyle, EdgeLabels}] = {Red, "bye"};gg = CompleteGraph[4, VertexStyle -> {1 -> Blue}, VertexLabels -> {1 -> "one"}, EdgeStyle -> {12 -> Blue}, EdgeLabels -> {12 -> "hello"}]AnnotationValue[{g, 1}, VertexLabels]=.;gAnnotationValue[{g, 12}, EdgeLabels]=.;gAnnotationValue 适用于无向图:
AnnotationValue[{[image], 12}, EdgeStyle]AnnotationValue[{[image], 12}, EdgeStyle]AnnotationValue[{[image], 12}, EdgeStyle]AnnotationValue[{[image], 12}, EdgeStyle]AnnotationValue[{[image], 12}, EdgeWeight]顶点注释 (3)
标准顶点注释包括 VertexStyle:
g = CompleteGraph[4, VertexSize -> Small]AnnotationValue[{g, 4}, VertexStyle] = Red;gAnnotationValue[{g, 1}, VertexLabels] = "one";gAnnotationValue[{g, 1}, VertexSize] = Large;gAnnotationValue[{g, 1}, VertexShape] = [image];gAnnotationValue[{g, 2}, VertexShapeFunction] = "Square";g非视觉注释包括 VertexWeight:
AnnotationValue[{g, 1}, VertexWeight] = 100;AnnotationValue[{g, 1}, VertexWeight]g = CompleteGraph[4];AnnotationValue[{g, 2}, "Material"] = "Wood";AnnotationValue[{g, 2}, "Material"]g = CompleteGraph[4]AnnotationValue[{g, 1}, VertexLabels] = "vertex";gAnnotationValue[{%, 1}, VertexLabels]边注释 (3)
标准边注释包括 EdgeStyle:
g = CompleteGraph[4]AnnotationValue[{g, 12}, EdgeStyle] = Brown;gAnnotationValue[{g, 12}, EdgeLabels] = 12;gAnnotationValue[{g, 34}, EdgeShapeFunction] = {"HalfFilledDoubleArrow", "ArrowSize" -> .2};g非视觉注释包括 EdgeWeight:
AnnotationValue[{g, 12}, EdgeWeight] = 42;AnnotationValue[{g, 12}, EdgeWeight]g = CompleteGraph[4];AnnotationValue[{g, 24}, "Resistance"] = 50.;AnnotationValue[{g, 24}, "Resistance"]g = CompleteGraph[4]AnnotationValue[{g, 12}, EdgeLabels] = "edge";gAnnotationValue[{g, 12}, EdgeLabels]区域 (3)
从 CSGRegion 中提取注释:
CSGRegion["Union", {Style[Ball[], Red], Style[Cuboid[], Blue]}]AnnotationValue[{%, {1}}, "CSGRegionStyle"]csg = CSGRegion["Union", {Ball[], Cuboid[]}]AnnotationValue[csg, "CSGRegionStyle"] = Red;csgcsg = CSGRegion["Union", {Style[Ball[], Red], Style[Cuboid[], Blue]}]AnnotationValue[{csg, {1}}, "CSGRegionStyle"]=.;csg音频 (2)
注释 Audio 对象:
a = Import["ExampleData/rule30.wav"];
a = Annotate[a, "Label" -> {.3 -> "val1", .6 -> "val2"}]使用 AnnotationValue 提取注释:
AnnotationValue[a, "Label"]使用 AudioAnnotate 注释 Audio 对象:
a = Import["ExampleData/rule30.wav"];
a = AudioAnnotate[a, {"Loud", "Transients"}]使用 AnnotationValue 提取多个注释:
AnnotationValue[a, {"Loud", "Transients"}]//Column应用 (5)
使用 Do 设置多个注释值:
g = CompleteGraph[8, VertexSize -> Medium]Do[AnnotationValue[{g, v}, VertexStyle] = Black, {v, {4, 5, 6, 7, 8}}]gDo[AnnotationValue[{g, v[[1]]}, VertexStyle] = v[[2]], {v, {{1, Red}, {2, Green}, {3, Blue}, {6, Orange}}}]g使用 Table 建立注释值列表:
Table[AnnotationValue[{g, v}, VertexStyle], {v, VertexList[g]}]GraphicsGrid[{Graphics[{#, Disk[]}]& /@ %}]g = CompleteGraph[5]Do[AnnotationValue[{g, e}, EdgeWeight] = RandomReal[], {e, EdgeList[g]}]Table[AnnotationValue[{g, e}, EdgeWeight], {e, EdgeList[g]}]{min, max} = {Min[#], Max[#]}&@%Do[AnnotationValue[{g, e}, EdgeStyle] = AbsoluteThickness[Rescale[AnnotationValue[{g, e}, EdgeWeight], {min, max}, {1, 4}]], {e, EdgeList[g]}]gg = CompleteGraph[5]path = {3, 4, 1, 5, 2};Do[AnnotationValue[{g, e}, EdgeStyle] = Red, {e, EdgeList[PathGraph[path]]}]AnnotationValue[{g, path[[1]]}, VertexLabels] = "Start";
AnnotationValue[{g, path[[-1]]}, VertexLabels] = "End";g按照 EdgeList 给定的顺序动态突出显示边:
Dynamic[g, Initialization :> (g = GridGraph[{5, 5}])]Do[AnnotationValue[{g, e}, EdgeStyle] = Directive[Thick, Blue]; Pause[0.2], {e, EdgeList[g]}]//AbsoluteTimingDynamic[g, Initialization :> (g = CompleteKaryTree[3, 3, ImageSize -> Medium, VertexSize -> Medium])]BreadthFirstScan[g, {"DiscoverVertex" -> ((AnnotationValue[{g, #}, VertexStyle] = Red;Pause[0.25]) &), "FrontierEdge" -> ((AnnotationValue[{g, #}, EdgeStyle] = Blue;Pause[0.25]) &) }];属性和关系 (5)
使用 Annotation 作为包装,在 Graph 之类的函数中指定注释:
Graph[{Annotation[1, {VertexSize -> Medium, VertexStyle -> Red}], 2, 3}, {12, 23, 31}]对于未定义的注释,AnnotationValue 返回 $Failed:
AnnotationValue[{CompleteGraph[4], 1}, VertexWeight]使用 AnnotationKeys 测试注释的存在:
g = CompleteGraph[4, VertexLabels -> {1 -> one, 4 -> four}]MemberQ[AnnotationKeys[{g, 1}], VertexLabels]Cases[VertexList[g], v_ /; MemberQ[AnnotationKeys[{g, v}], VertexLabels] :> v -> AnnotationValue[{g, v}, VertexLabels]]使用 Annotate 设置注释而不更改原始图:
g = CompleteGraph[4]Annotate[{g, 1}, VertexSize -> Medium]g使用 AnnotationDelete 删除注释而不更改原始图:
g = CompleteGraph[4, VertexStyle -> {1 -> Red}, VertexSize -> Small]AnnotationDelete[{g, 1}, VertexStyle]g可能存在的问题 (2)
对于未定义注释,AnnotationValue 返回 $Failed:
g = CompleteGraph[4, VertexSize -> {1 -> Small}]AnnotationValue[{g, 1}, vertexSize]使用 AnnotationKeys 测试注释的存在:
MemberQ[AnnotationKeys[{g, 1}], VertexSize]MemberQ[AnnotationKeys[{g, 1}], vertexSize]即使存在注释值,AnnotationValue 也可能返回 $Failed:
g = Graph[{Annotation[1, "Result" -> $Failed], 2, 3}, {12, 23, 31}]AnnotationValue[{g, 1}, "Result"]使用 AnnotationKeys 检查实际注释值:
MemberQ[AnnotationKeys[{g, 1}], "Result"]文本
Wolfram Research (2020),AnnotationValue,Wolfram 语言函数,https://reference.wolfram.com/language/ref/AnnotationValue.html (更新于 2025 年).
CMS
Wolfram 语言. 2020. "AnnotationValue." Wolfram 语言与系统参考资料中心. Wolfram Research. 最新版本 2025. https://reference.wolfram.com/language/ref/AnnotationValue.html.
APA
Wolfram 语言. (2020). AnnotationValue. Wolfram 语言与系统参考资料中心. 追溯自 https://reference.wolfram.com/language/ref/AnnotationValue.html 年
BibTeX
@misc{reference.wolfram_2026_annotationvalue, author="Wolfram Research", title="{AnnotationValue}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/AnnotationValue.html}", note=[Accessed: 16-August-2026]}
BibLaTeX
@online{reference.wolfram_2026_annotationvalue, organization={Wolfram Research}, title={AnnotationValue}, year={2025}, url={https://reference.wolfram.com/language/ref/AnnotationValue.html}, note=[Accessed: 16-August-2026]}