is an option that allows specification of annotations to objects and items in objects.
AnnotationRules
is an option that allows specification of annotations to objects and items in objects.
Details
- Typically used to specify annotations to objects and items in objects.
- Possible objects with items that can be annotated:
-
Audio time points and time intervals BoundaryMeshRegion mesh cells CSGRegion geometric regions Graph vertices and edges MeshRegion mesh cells - AnnotationRules is always converted to an optimized standard form with structure.
- The AnnotationRules option can be used to specify inheritance of annotations in constructs such as Subgraph, EdgeAdd and GraphUnion.
- Typical settings for inheritance of annotations include:
-
Inherited inherit all annotations Automatic use automatic inheritance of annotations None set no inheritance
Examples
open all close allBasic Examples (2)
Specify a cell annotation in mesh:
mr = MengerMesh[1, AnnotationRules -> {{2, 1} -> {"marker" -> 1}}];Retrieve the custom annotation:
AnnotationValue[{mr, {2, 1}}, "marker"]Inherit all annotations of the graph:
graph = [image];Subgraph[graph, {28, 38, 48, 27, 37, 47, 26, 36, 46}, AnnotationRules -> Inherited]Use automatic inheritance of annotations:
Subgraph[graph, {28, 38, 48, 27, 37, 47, 26, 36, 46}, AnnotationRules -> Automatic]Subgraph[graph, {28, 38, 48, 27, 37, 47, 26, 36, 46}, AnnotationRules -> None]Scope (12)
Graphs & Networks (12)
Graph annotations (8)
Graph[{12, 23, 31}, AnnotationRules -> {1 -> {VertexLabels -> "hello"}}]Graph[{12, 23, 31}, AnnotationRules -> {12 -> {EdgeLabels -> "hello"}}]Set annotations for the graph itself:
Graph[{12, 23, 31}, AnnotationRules -> {"GraphProperties" -> {"Message" -> "hello"}}]AnnotationValue[%, "Message"]Set default annotations for vertices:
Graph[{12, 23, 31}, AnnotationRules -> {"DefaultVertexProperties" -> {VertexStyle -> Red}}, VertexSize -> Small]Graph[{12, 23, 31}, AnnotationRules -> {"DefaultEdgeProperties" -> {EdgeStyle -> Dashed}}]AnnotationRules works with undirected graphs:
Graph[{1, 2, 3}, {12, 23, 31}, AnnotationRules -> {12 -> {EdgeStyle -> Brown}}]Graph[{1, 2, 3}, {12, 23, 31}, AnnotationRules -> {12 -> {EdgeStyle -> Dashed}}, EdgeStyle -> Arrowheads[Small]]Graph[{1, 2, 3}, {12, 23, 23, 23, 31}, AnnotationRules -> {12 -> {EdgeStyle -> Brown}}]Graph[{1, 2, 3}, {12, 23, 31}, AnnotationRules -> {12 -> {EdgeStyle -> Dashed}}, EdgeStyle -> Arrowheads[0.08]]Graph[{1, 2, 3}, {12, 23, 31}, EdgeWeight -> {0.5, 1, 1}, AnnotationRules -> {12 -> {EdgeStyle -> Dashed}}]Vertex annotations (2)
Standard vertex annotations include VertexStyle:
Graph[{12, 23, 31}, AnnotationRules -> {1 -> {VertexStyle -> Red}}]Graph[{12, 23, 31}, AnnotationRules -> {1 -> {VertexLabels -> "hello"}}]Graph[{12, 23, 31}, AnnotationRules -> {1 -> {VertexSize -> Small}}]Graph[{12, 23, 31}, VertexSize -> Medium, AnnotationRules -> {1 -> {VertexShape -> [image]}}]Graph[{12, 23, 31}, AnnotationRules -> {1 -> {"Material" -> "Wood"}}]AnnotationValue[{%, 1}, "Material"]Edge annotations (2)
Standard edge annotations include EdgeStyle:
Graph[{12, 23, 31}, AnnotationRules -> {12 -> {EdgeStyle -> Brown}}]Graph[{12, 23, 31}, AnnotationRules -> {12 -> {EdgeLabels -> "hello"}}]Graph[{12, 23, 31}, AnnotationRules -> {12 -> {EdgeShapeFunction -> "DashedLine"}}]Graph[{12, 23, 31}, AnnotationRules -> {12 -> {"Resistance" -> 50.}}]AnnotationValue[{%, 12}, "Resistance"]Applications (4)
Graph[{1, 2, 3, 4, 5, 6}, {41, 12, 23, 25, 36, 45, 56}, AnnotationRules -> {41 -> {EdgeLabels -> "Voltage source"}, 12 -> {EdgeLabels -> "Resistance"},
23 -> {EdgeLabels -> "Inductance"},
25 -> {EdgeLabels -> "Capactitance"},
36 -> {EdgeLabels -> "Bulb"},
45 -> {EdgeLabels -> "Wire"},
56 -> {EdgeLabels -> "Wire"}}, GraphLayout -> "SpringEmbedding", VertexSize -> 0, ImagePadding -> {{30, 10}, {5, 5}}]Create a graph with various annotations associated with the vertices:
g = Graph[{Annotation[1, {VertexWeight -> 42, VertexLabels -> "hello"}], Annotation[2, {"Material" -> "Wood", VertexStyle -> Green}], Annotation[3, VertexSize -> Medium]}, {12, 23, Annotation[31, EdgeStyle -> Dashed]}]Options uses AnnotationRules to handle some of the annotations:
Options[g]Generate an input form of the graph:
Graph@@@HoldForm[Evaluate[{VertexList[g], EdgeList[g], Options[g]}]]ReleaseHold[%]% == gUse Table to set similar annotations for many items:
CycleGraph[15, AnnotationRules -> Table[v -> {VertexSize -> 0.2 + 0.2Mod[v, 5], VertexStyle -> Hue[(v/15), 1, 1]}, {v, 15}]]Use Thread when annotation values are available in lists:
values = {{Small, Green}, {Small, White}, {Small, Green}, {Medium, Red}, {Medium, Green}, {Medium, White}};CycleGraph[6, AnnotationRules -> Table[v -> Thread[{VertexSize, VertexStyle} -> values[[v]]], {v, 6}]]Related Guides
Text
Wolfram Research (2019), AnnotationRules, Wolfram Language function, https://reference.wolfram.com/language/ref/AnnotationRules.html (updated 2025).
CMS
Wolfram Language. 2019. "AnnotationRules." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2025. https://reference.wolfram.com/language/ref/AnnotationRules.html.
APA
Wolfram Language. (2019). AnnotationRules. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/AnnotationRules.html
BibTeX
@misc{reference.wolfram_2026_annotationrules, author="Wolfram Research", title="{AnnotationRules}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/AnnotationRules.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_annotationrules, organization={Wolfram Research}, title={AnnotationRules}, year={2025}, url={https://reference.wolfram.com/language/ref/AnnotationRules.html}, note=[Accessed: 12-June-2026]}