PropertyValue[{obj,item},name]
gives the property value associated with name for item in obj.
PropertyValue[{obj,itemspec},name]
gives the property values associated with name for items indicated by itemspec in obj.
PropertyValue[…,{name1,name2,…}]
gives a list of property values associated with name1, name2, etc.
PropertyValue
PropertyValue[{obj,item},name]
gives the property value associated with name for item in obj.
PropertyValue[{obj,itemspec},name]
gives the property values associated with name for items indicated by itemspec in obj.
PropertyValue[…,{name1,name2,…}]
gives a list of property values associated with name1, name2, etc.
Details
- Properties are used to store and manipulate name->value pairs for specific named items within an object such as Graph, MeshRegion, and BoundaryMeshRegion.
- The item specification itemspec typically has the form {collection,index}.
- The index can typically have the following forms:
-
ind a single index {ind1,ind2,…} a list of indexes All all possible indexes in collection patt indexes that match patt in collection - The collection can typically have the following forms:
-
col a single collection {col1,col2,…} a list of collections All all possible collections patt collections that match patt - The item specification itemspec of the form collection refers to the default value for all indexes in the collection.
- PropertyValue[{obj,itemspec},name] returns $Failed whenever there is no property value available for name.
- PropertyValue[{obj,itemspec},name]=val can be used to modify the property value.
- Objects that support properties include Graph, MeshRegion, and BoundaryMeshRegion. Item specifications for each type of object is given in their reference pages.
Examples
open all close allBasic Examples (1)
Generate a complete graph with properties:
g = CompleteGraph[4, VertexLabels -> {1 -> "one"}]Retrieve the property value associated with a property name:
PropertyValue[{g, 1}, VertexLabels]PropertyValue[{g, 1}, VertexLabels] = "two";gPropertyValue[{g, 1}, VertexLabels]=.;gScope (8)
Basic Uses (4)
Set a property value for vertex 1:
g = CompleteGraph[4]PropertyValue[{g, 1}, VertexLabels] = "vertex";gRetrieve the property value for vertex 1:
PropertyValue[{%, 1}, VertexLabels]Set a property value for the edge 12:
g = CompleteGraph[4]PropertyValue[{g, 12}, EdgeLabels] = "edge";gRetrieve the property value for the edge 12:
PropertyValue[{g, 12}, EdgeLabels]Unset properties for vertices:
g = CompleteGraph[4, VertexStyle -> {1 -> Blue}, VertexLabels -> {1 -> "one"}, EdgeStyle -> {12 -> Blue}, EdgeLabels -> {12 -> "hello"}]PropertyValue[{g, 1}, VertexLabels]=.;gPropertyValue[{g, 12}, EdgeLabels]=.;gPropertyValue returns $Failed for undefined properties:
PropertyValue[{CompleteGraph[4], 1}, VertexWeight]Vertex Properties (2)
Standard vertex properties include VertexStyle:
g = CompleteGraph[4, VertexSize -> Small]PropertyValue[{g, 4}, VertexStyle] = Red;gPropertyValue[{g, 1}, VertexLabels] = "one";gPropertyValue[{g, 1}, VertexSize] = Large;gPropertyValue[{g, 1}, VertexShape] = [image];gPropertyValue[{g, 2}, VertexShapeFunction] = "Square";gNon-visual properties include VertexWeight:
PropertyValue[{g, 1}, VertexWeight] = 100;PropertyValue[{g, 1}, VertexWeight]g = CompleteGraph[4];PropertyValue[{g, 2}, "Material"] = "Wood";PropertyValue[{g, 2}, "Material"]Edge Properties (2)
Standard edge properties include EdgeStyle:
g = CompleteGraph[4]PropertyValue[{g, 12}, EdgeStyle] = Brown;gPropertyValue[{g, 12}, EdgeLabels] = 12;gNon-visual properties include EdgeWeight:
PropertyValue[{g, 12}, EdgeWeight] = 42;PropertyValue[{g, 12}, EdgeWeight]g = CompleteGraph[4];PropertyValue[{g, 24}, "Resistance"] = 50.;PropertyValue[{g, 24}, "Resistance"]Applications (5)
Use Do to set several property values:
g = CompleteGraph[8, VertexSize -> Medium]Do[PropertyValue[{g, v}, VertexStyle] = Orange, {v, {4, 5, 6, 7, 8}}]gOr different property values for different items:
Do[PropertyValue[{g, v[[1]]}, VertexStyle] = v[[2]], {v, {{1, Red}, {2, Green}, {3, Blue}, {6, White}}}]gUse Table to build a list of property values:
Table[PropertyValue[{g, v}, VertexStyle], {v, VertexList[g]}]GraphicsGrid[{Graphics[{#, Disk[]}]& /@ %}]g = CompleteGraph[5]Do[PropertyValue[{g, e}, EdgeWeight] = Random[], {e, EdgeList[g]}]Table[PropertyValue[{g, e}, EdgeWeight], {e, EdgeList[g]}]{min, max} = {Min[#], Max[#]}&@%Set the edge thickness to reflect the edge weight:
Do[PropertyValue[{g, e}, EdgeStyle] = AbsoluteThickness[Rescale[PropertyValue[{g, e}, EdgeWeight], {min, max}, {1, 4}]], {e, EdgeList[g]}]gHighlight a path and mark the start point and endpoint:
g = CompleteGraph[5]path = {3, 4, 1, 5, 2};Highlight by setting edge style along the path and vertex labels for start point and endpoint:
Do[PropertyValue[{g, e}, EdgeStyle] = Red, {e, EdgeList[PathGraph[path]]}]PropertyValue[{g, path[[1]]}, VertexLabels] = "Start";
PropertyValue[{g, path[[-1]]}, VertexLabels] = "End";gDynamically highlight the edges in the order given by EdgeList:
Dynamic[g, Initialization :> (g = GridGraph[{5, 5}])]Do[PropertyValue[{g, e}, EdgeStyle] = Directive[Thick, Blue]; Pause[0.2], {e, EdgeList[g]}]//AbsoluteTimingDynamically visualize breadth-first search:
Dynamic[g, Initialization :> (g = CompleteKaryTree[3, 3, ImageSize -> Medium, VertexSize -> Medium])]BreadthFirstScan[g, {"DiscoverVertex" -> ((PropertyValue[{g, #}, VertexStyle] = Red;Pause[0.25]) &), "FrontierEdge" -> ((PropertyValue[{g, #}, EdgeStyle] = Blue;Pause[0.25]) &) }];Properties & Relations (4)
Use Property as a wrapper to specify properties in functions such as Graph:
Graph[{Property[1, {VertexSize -> Medium, VertexStyle -> Red}], 2, 3}, {12, 23, 31}]Use PropertyList to test for the presence of a property:
g = CompleteGraph[4, VertexLabels -> {1 -> one, 4 -> four}]MemberQ[PropertyList[{g, 1}], VertexLabels]Generate a list of vertex label rules:
Cases[VertexList[g], v_ /; MemberQ[PropertyList[{g, v}], VertexLabels] :> v -> PropertyValue[{g, v}, VertexLabels]]Use SetProperty to set a property without changing the original:
g = CompleteGraph[4]SetProperty[{g, 1}, VertexSize -> Medium]The original graph is unchanged:
gUse RemoveProperty to remove a property without changing the original:
g = CompleteGraph[4, VertexStyle -> {1 -> Red}, VertexSize -> Small]RemoveProperty[{g, 1}, VertexStyle]The original graph is unchanged:
gPossible Issues (3)
PropertyValue returns $Failed for undefined properties:
g = CompleteGraph[4, VertexSize -> {1 -> Small}]PropertyValue[{g, 1}, vertexSize]Use PropertyList to test for the presence of a property:
MemberQ[PropertyList[{g, 1}], VertexSize]MemberQ[PropertyList[{g, 1}], vertexSize]PropertyValue may return $Failed even when a property value exists:
g = Graph[{Property[1, "Result" -> $Failed], 2, 3}, {12, 23, 31}]PropertyValue[{g, 1}, "Result"]Use PropertyList to check for actual property values:
MemberQ[PropertyList[{g, 1}], "Result"]PropertyValue returns the first value associated with a property for identical edges:
g = Graph[{Labeled[12, "edge1"], Labeled[12, "edge2"]}];PropertyValue[{g, 12}, EdgeLabels]See Also
Related Guides
Text
Wolfram Research (2010), PropertyValue, Wolfram Language function, https://reference.wolfram.com/language/ref/PropertyValue.html (updated 2015).
CMS
Wolfram Language. 2010. "PropertyValue." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2015. https://reference.wolfram.com/language/ref/PropertyValue.html.
APA
Wolfram Language. (2010). PropertyValue. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/PropertyValue.html
BibTeX
@misc{reference.wolfram_2026_propertyvalue, author="Wolfram Research", title="{PropertyValue}", year="2015", howpublished="\url{https://reference.wolfram.com/language/ref/PropertyValue.html}", note=[Accessed: 15-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_propertyvalue, organization={Wolfram Research}, title={PropertyValue}, year={2015}, url={https://reference.wolfram.com/language/ref/PropertyValue.html}, note=[Accessed: 15-June-2026]}