Mathematica Asked on January 3, 2021
How to change color and size at the same time of some vertices of a graph?
I am trying to do it more than an hour but nothing seems to work.
I can do it either for color or for size but not both at the same time.
I want to have big blue disks.
HighlightGraph[GridGraph[{3, 3}], {1, 2}, VertexSize -> .2]
HighlightGraph[GridGraph[{3, 3}], Style[{1, 2}, Blue]]
This does not work:
HighlightGraph[GridGraph[{3, 3}], {1, 2}, VertexSize -> .2,Style[{1, 2}, Blue]]
Update:
Why the following code changes size of all vertices, I want to change size only of the green ones.
HighlightGraph[
GridGraph[{3, 3}], {Style[PathGraph[{3, 2, 1, 4, 7, 8, 9, 6, 5}],
Red, Thickness[0.01]], Style[{3, 5}, Green]}, VertexSize -> 0.2]
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
Correct answer by Jason B. on January 3, 2021
You can specify VertexStyle
directives using Style
and
{Alternatives@@vlist1 -> optionvalue1, ...}
for setting the values of other Vertex*
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]
Property[vlist, {options}]
(Annotation[vlist, {options}]
in version 12.1+) to specify Vertex*
options for vlist
: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"}]}]
Answered by kglr on January 3, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP