How to change vertex color and vertex size at the same time of Graph
This input
HighlightGraph[GridGraph[{3, 3}], {1, 2}, VertexSize -> .2,Style[{1, 2}, Blue]]
is not valid syntax for HighlightGraph
. VertexSize
is an Option
and so it must come after all the other arguments
HighlightGraph[GridGraph[{3, 3}], Style[{1, 2}, Blue],
VertexSize -> .2]
Just for fun, here is another way you can modify properties of vertices and edges:
g = GridGraph[{3, 3}];
AnnotationValue[{g, {1, 2}}, VertexSize] = .2;
AnnotationValue[{g, {1, 2}}, VertexStyle] = Blue;
g
You can specify VertexStyle
directives using Style
and
- use the form
{Alternatives@@vlist1 -> optionvalue1, ...}
for setting the values of otherVertex*
options:
HighlightGraph[GridGraph[{3, 3}],
{Style[PathGraph[{3, 2, 1, 4, 7, 8, 9, 6, 5}], Red, Thickness[0.01]],
Style[{3, 5}, Green, EdgeForm[{Purple, Opacity[1], Thickness[.02]}]]},
VertexSize -> {3 | 5 -> .2, 1 -> .3},
VertexShapeFunction -> {3 | 5 -> "Square", 1 -> "ConcaveHexagon"},
VertexLabels -> {3 | 5 -> Placed["Name", Center]},
VertexLabelStyle -> 16]
- or use
Property[vlist, {options}]
(Annotation[vlist, {options}]
in version 12.1+) to specifyVertex*
options forvlist
:
HighlightGraph[GridGraph[{3, 3}],
{Style[PathGraph[{3, 2, 1, 4, 7, 8, 9, 6, 5}], Red, Thickness[0.01]],
Property[Style[{3, 5}, Green, EdgeForm[{Opacity[1], Blue, Thickness[.02]}]],
{VertexSize -> 0.2, VertexLabels -> Placed["Name", Center],
VertexShapeFunction -> "Hexagon"}]}]