Annotate
更多信息
- 通常用于存储对象或对象中各项的 key->value 对.
- Annotate 返回带有新注释或修改注释的指定对象.
- 带有可注释项的可能对象:
-
Audio 时间点和时间间隔 BoundaryMeshRegion 网格单元 CSGRegion 几何区域 Graph 顶点和边 MeshRegion 网格单元 - 每种对象类型的项规范 itemspec 在其参考页面中给出.
范例
打开所有单元 关闭所有单元基本范例 (3)
g = CompleteGraph[4]Annotate[{g, 1}, VertexLabels -> "one"]Annotate[{g, 12}, EdgeStyle -> Red]Annotate[{MengerMesh[2], {1, "Boundary"}}, MeshCellStyle -> Red]突出显示 CSGRegion 中的一个区域:
Annotate[{CSGRegion[{Ball[], Cuboid[]}], {2}}, "CSGRegionStyle" -> Red]范围 (17)
图和网络 (11)
图注释 (7)
CompleteGraph[4];Annotate[{[image], 1}, VertexSize -> Small]Annotate[{[image], 12}, EdgeLabels -> "hello"]CompleteGraph[4, VertexSize -> Medium];Annotate[{[image], 1}, {VertexStyle -> Magenta, VertexLabels -> "hello"}]Annotate[{[image], 12}, {EdgeStyle -> Magenta, EdgeLabels -> "hello"}]Annotate 适用于无向图:
CycleGraph[3];Annotate[{[image], 12}, {EdgeStyle -> Brown}]CycleGraph[3, DirectedEdges -> True, EdgeStyle -> Arrowheads[Small]];Annotate[{[image], 12}, {EdgeLabels -> "hello"}]Graph[{1, 2, 3}, {12, 23, 23, 23, 31}];Annotate[{[image], 12}, {EdgeStyle -> Brown}]Graph[{1, 2, 3}, {12, 23, 31}, EdgeStyle -> Arrowheads[0.08]];Annotate[{[image], 12}, {EdgeStyle -> Brown}]With[{g = CycleGraph[3], w = 0.3Range[3],
pl = {Above, Right, Right} /. {Right -> {1 / 2, {-0.4, 1 / 2}}, Above -> {1 / 2, {1 / 2, 0}}}},
Graph[VertexList[g], EdgeList[g], EdgeWeight -> w, VertexShapeFunction -> "Name", EdgeLabels -> Thread[EdgeList[g] -> MapThread[Placed, {w, pl}]], VertexCoordinates -> GraphEmbedding[g]]];Annotate[{[image], 12}, {EdgeStyle -> Dashed}]顶点注释 (2)
标准顶点注释包括 VertexStyle:
g = CompleteGraph[4, VertexSize -> Medium]Annotate[{g, 4}, VertexStyle -> Red]Annotate[{g, 1}, VertexLabels -> "one"]Annotate[{g, 1}, VertexSize -> Tiny]Annotate[{g, 1}, VertexShape -> [image]]Annotate[{g, 2}, VertexShapeFunction -> "Square"]非可视注释包括 VertexWeight:
Annotate[{g, 1}, VertexWeight -> 100]AnnotationValue[{%, 1}, VertexWeight]CompleteGraph[4];Annotate[{[image], 2}, "Material" -> "Wood"]AnnotationValue[{%, 2}, "Material"]边注释 (2)
标准边注释包括 EdgeStyle:
g = CompleteGraph[4]Annotate[{g, 12}, EdgeStyle -> Brown]Annotate[{g, 12}, EdgeLabels -> 12]Annotate[{g, 34}, EdgeShapeFunction -> "HalfFilledDoubleArrow"]不可见的注释,包括 EdgeWeight:
Annotate[{g, 12}, EdgeWeight -> 42]AnnotationValue[{%, 12}, EdgeWeight]CompleteGraph[4];Annotate[{[image], 24}, "Resistance" -> 50.]AnnotationValue[{%, 24}, "Resistance"]区域 (6)
BoundaryMeshRegion (2)
Annotate 一个点:
bmr = BoundaryMesh[Cube[]];Annotate[{bmr, {0, 7}}, MeshCellStyle -> {PointSize[Large], Red}]Annotate[{bmr, {1, 9}}, MeshCellStyle -> {Thick, Red}]Annotate[{bmr, {2, 6}}, MeshCellStyle -> {Red}]Annotate 所有特定维度的网格单元:
bmr = BoundaryMesh[Cube[]];Table[Annotate[{bmr, {d}}, MeshCellStyle -> Red], {d, {0, 1, 2}}]MeshRegion (2)
Annotate 一个点:
mr = MengerMesh[1];Annotate[{mr, {0, 7}}, MeshCellStyle -> {PointSize[Large], Red}]Annotate[{mr, {1, 2}}, MeshCellStyle -> {Thick, Red}]Annotate[{mr, {2, 1}}, MeshCellStyle -> {Red}]Annotate 特定维度的所有网格单元:
mr = MengerMesh[2];Table[Annotate[{mr, {d}}, MeshCellStyle -> Red], {d, {0, 1, 2}}]CSGRegion (2)
csg = CSGRegion["Union", {Ball[], Cuboid[]}]Annotate[csg, "CSGRegionStyle" -> Red]csg = CSGRegion["Union", {Ball[], Cuboid[]}]Annotate[{csg, {2}}, "CSGRegionStyle" -> Red]应用 (3)
g = CycleGraph[8, VertexSize -> Large]Fold[Annotate[{#1, #2}, VertexStyle -> ColorData[45, #2]]&, g, Range[1, 5]]FoldList[Annotate[{#1, #2}, VertexStyle -> ColorData[45, #2]]&, g, Range[1, 6]]g = CompleteGraph[4]Annotate[{g, 1}, VertexSize -> Medium]Annotate[{g, 2}, VertexSize -> Medium]g = CompleteKaryTree[4, 3, DirectedEdges -> True]ListAnimate[Reap[BreadthFirstScan[g, {"FrontierEdge" -> (Sow[Annotate[{g, #}, EdgeStyle -> Red]]& )}]][[2, 1]], DefaultDuration -> Length[EdgeList[g]] / 2, SaveDefinitions -> True]属性和关系 (6)
使用 Annotation 作为包装,在 Graph 之类的函数中指定注释:
Graph[{Annotation[1, {VertexSize -> Medium, VertexStyle -> Red}], 2, 3}, {12, 23, 31}]使用 AnnotationValue 提取值:
g = CompleteGraph[4, VertexStyle -> {1 -> Red}, VertexSize -> Small]AnnotationValue[{g, 1}, VertexStyle]对于未定义的注释,返回值 $Failed:
AnnotationValue[{g, 1}, "foo"]MemberQ[AnnotationKeys[{g, 1}], "foo"]使用 AnnotationValue 在图中设置注释:
g = CompleteGraph[4]AnnotationValue[{g, 1}, VertexSize] = Small;g使用 AnnotationValue 取消图的注释:
g = CompleteGraph[4, VertexSize -> {1 -> Small}]AnnotationValue[{g, 1}, VertexSize]=.;g使用 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]]使用 AnnotationDelete 删除注释而不更改原始图:
g = CompleteGraph[4, VertexStyle -> {1 -> Red}, VertexSize -> Small]AnnotationDelete[{g, 1}, VertexStyle]g可能存在的问题 (1)
AnnotationValue 通常比 Annotate 的速度快:
g = CycleGraph[1000];Timing@Do[AnnotationValue[{g, v}, VertexWeight] = RandomReal[], {v, VertexList[g]}]g = CycleGraph[1000];Timing@Do[g = Annotate[{g, v}, VertexWeight -> RandomReal[]], {v, VertexList[g]}]文本
Wolfram Research (2020),Annotate,Wolfram 语言函数,https://reference.wolfram.com/language/ref/Annotate.html (更新于 2025 年).
CMS
Wolfram 语言. 2020. "Annotate." Wolfram 语言与系统参考资料中心. Wolfram Research. 最新版本 2025. https://reference.wolfram.com/language/ref/Annotate.html.
APA
Wolfram 语言. (2020). Annotate. Wolfram 语言与系统参考资料中心. 追溯自 https://reference.wolfram.com/language/ref/Annotate.html 年
BibTeX
@misc{reference.wolfram_2026_annotate, author="Wolfram Research", title="{Annotate}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/Annotate.html}", note=[Accessed: 16-August-2026]}
BibLaTeX
@online{reference.wolfram_2026_annotate, organization={Wolfram Research}, title={Annotate}, year={2025}, url={https://reference.wolfram.com/language/ref/Annotate.html}, note=[Accessed: 16-August-2026]}