is an option and annotation for Graph and related functions that specifies a function to use to generate primitives for rendering each vertex.
VertexShapeFunction
is an option and annotation for Graph and related functions that specifies a function to use to generate primitives for rendering each vertex.
Details
- VertexShapeFunction is also known as node shape and shape function.
- VertexShapeFunction is typically used to control the visual appearance of vertices and to display additional information.
- The following option settings can be used:
-
Automatic the default vertex function None do not render vertices "Name" use the vertex name "nfunc" a named vertex function func a general vertex function {vivfi,…} use vertex function vfi for vertex vi {pattivfi,…} use vfi for vertices matching the pattern patti - VertexShapeFunction->func specifies that each vertex should be rendered with the primitives provided by func[{x,y},v,{w,h}], where {x,y} is the center, v the vertex name, and {w,h} the width and the height.
- In 3D, VertexShapeFunction->func specifies that each vertex should be rendered with the primitives provided by func[{x,y,z},v,{w,h,d}], where {x,y,z} is the center, v the vertex name and {w,h,d} the width and the height.
- The vertex function func should render the vertex primitives in the bounding box {{x-w,x+w},{y-h,y+h}} in 2D and {{x-w,x+w},{y-h,y+h},{z-d,z+d}} in 3D automatically computed by layout algorithms.
- The following named arguments can be used in the vertex function func:
-
#Coordinates center {x,y} or {x,y,z} #Vertex vertex name v #Size width and height {w,h} - Use ResourceData["VertexShapeFunction"] to get a list of all named vertex functions "nfunc".
- Possible vertex shapes "nfunc" include:
- The wrapper Annotation[v,VertexShapeFunction->f] can be used when creating graphs in functions such as Graph etc.
Examples
open all close allBasic Examples (4)
Draw vertices using a predefined vertex function:
Graph[{12, 23, 31}, VertexShapeFunction -> "Square", VertexSize -> 0.2]Specify a vertex function for an individual vertex:
Graph[{12, 23, 31}, VertexShapeFunction -> { 1 -> "Square"}, VertexSize -> 0.2]Use an Annotation wrapper to specify individual vertex functions:
Graph[{Annotation[1, VertexShapeFunction -> "Square"], 2, 3}, {12, 23, 31}, VertexSize -> 0.2]Draw vertices by running a program:
vf[{xc_, yc_}, name_, {w_, h_}] :=
Block[{xmin = xc - w, xmax = xc + w, ymin = yc - h, ymax = yc + h},
Polygon[{{xmin, ymin}, {xmax, ymax}, {xmin, ymax}, {xmax, ymin}}]
];CompleteGraph[4, VertexShapeFunction -> vf, VertexSize -> 0.2]Scope (13)
VertexShapeFunction Specification (9)
VertexShapeFunction can be used for general graphs:
{Graph[{12, 23, 31}, VertexShapeFunction -> "Square", VertexSize -> 0.2], PathGraph[Range[25], VertexShapeFunction -> "Square", VertexSize -> 0.2]}AdjacencyGraph[{{0, 1, 1}, {1, 0, 1}, {1, 1, 0}}, VertexShapeFunction -> "Square", VertexSize -> 0.2]{PetersenGraph[5, 2, VertexShapeFunction -> "Square", VertexSize -> 0.2], GridGraph[{4, 4}, VertexShapeFunction -> "Square", VertexSize -> 0.2]}RandomGraph[UniformGraphDistribution[10, 20], VertexShapeFunction -> "Square", VertexSize -> 0.2]Use VertexShapeFunction in an Annotation wrapper:
Graph[{Annotation[1, VertexShapeFunction -> "Square"], 2, 3}, {12, 23, 31}, VertexSize -> 0.2]HighlightGraph[GridGraph[{3, 3}, VertexSize -> 0.2], Annotation[5, VertexShapeFunction -> "Square"]]VertexShapeFunction works with patterns:
CompleteGraph[5, VertexShapeFunction -> {_ ? EvenQ -> "Star"}, VertexSize -> 0.2]VertexShapeFunction can be combined with VertexStyle:
vf1[{xc_, yc_}, name_, {w_, h_}] := Rectangle[{xc - w, yc - h}, {xc + w, yc + h}]Graph[{12, 23, 31}, VertexSize -> 0.2, VertexStyle -> Blue, VertexShapeFunction -> vf1]VertexShapeFunction has higher priority than VertexStyle:
vf2[{xc_, yc_}, name_, {w_, h_}] := {Red, Rectangle[{xc - w, yc - h}, {xc + w, yc + h}]}Graph[{12, 23, 31}, VertexSize -> 0.2, VertexStyle -> Blue, VertexShapeFunction -> vf2]VertexShapeFunction can be combined with VertexSize:
Graph[{12, 23, 31}, VertexShapeFunction -> "Star", VertexSize -> {1 -> Small, Medium}]VertexShapeFunction has higher priority than VertexShape:
Graph[{12, 23, 31}, VertexSize -> 0.2, VertexShapeFunction -> "Star", VertexShape -> [image]]VertexShapeFunction Gallery (4)
Get a list of built-in collections for VertexShapeFunction:
ResourceData["VertexShapeFunction"]Use built-in settings for VertexShapeFunction in the "Basic" collection:
ResourceData["VertexShapeFunction", "Basic"]Table[Graph[{12, 23, 31}, VertexShapeFunction -> vf, VertexSize -> 0.2, PlotLabel -> vf], {vf, {"Triangle", "Square", "Rectangle", "Pentagon", "Hexagon", "Octagon"}}]Table[Graph[{12, 23, 31}, VertexShapeFunction -> vf, VertexSize -> 0.2, PlotLabel -> vf], {vf, {"DownTrapezoid", "UpTrapezoid", "Parallelogram", "FiveDown", "Circle", "Diamond", "Star", "Capsule"}}]Use built-in settings for VertexShapeFunction in the "Rounded" collection:
ResourceData["VertexShapeFunction", "Rounded"]Table[Graph[{12, 23, 31}, VertexShapeFunction -> vf, VertexSize -> 0.2, PlotLabel -> Style[vf, 9]], {vf, ResourceData["VertexShapeFunction", "Rounded"]}]Use built-in settings for VertexShapeFunction in the "Concave" collection:
ResourceData["VertexShapeFunction", "Concave"]Table[Graph[{12, 23, 31}, VertexShapeFunction -> vf, VertexSize -> 0.2, PlotLabel -> Style[vf, 9]], {vf, ResourceData["VertexShapeFunction", "Concave"]}]Possible Issues (2)
Use Inset to render graphics or an image:
Graph[{12, 23, 31}, VertexShapeFunction -> (Inset[[image], #1, Center, 2 * #3]&), VertexSize -> .2]VertexShape takes graphics or images used for vertices:
Graph[{12, 23, 31}, VertexShape -> [image], VertexSize -> .2]With the setting VertexShapeFunctionNone, vertices are not displayed:
PetersenGraph[5, 4, VertexShapeFunction -> None]Use VertexSize0 to get connected lines:
PetersenGraph[5, 4, VertexShapeFunction -> None, VertexSize -> 0]Related Guides
Text
Wolfram Research (2010), VertexShapeFunction, Wolfram Language function, https://reference.wolfram.com/language/ref/VertexShapeFunction.html (updated 2026).
CMS
Wolfram Language. 2010. "VertexShapeFunction." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2026. https://reference.wolfram.com/language/ref/VertexShapeFunction.html.
APA
Wolfram Language. (2010). VertexShapeFunction. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/VertexShapeFunction.html
BibTeX
@misc{reference.wolfram_2026_vertexshapefunction, author="Wolfram Research", title="{VertexShapeFunction}", year="2026", howpublished="\url{https://reference.wolfram.com/language/ref/VertexShapeFunction.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_vertexshapefunction, organization={Wolfram Research}, title={VertexShapeFunction}, year={2026}, url={https://reference.wolfram.com/language/ref/VertexShapeFunction.html}, note=[Accessed: 12-June-2026]}