3
$\begingroup$

I have an adjacency matrix "am" and I want to color the nodes with four colors. Here I what do...

Needs["IGraphM`"];
G = AdjacencyGraph[am];
colors = ColorData[97] /@ Range[4];
Graph[G, GraphStyle -> "BasicBlack", VertexSize -> 1, 
 VertexLabels -> Placed["Name", Center], VertexLabelStyle -> 13, 
 EdgeStyle -> Darker@ColorData["Legacy", "IndianRed"], 
 VertexStyle -> 
  Thread[Range[VertexCount[G]] -> 
    colors[[IGKVertexColoring[G, 4][[1]]]]], 
 ImageSize -> {{600, 900}, {600, 900}}]

Note that with this approach, the vertex labels are are taken automatically from 1 to to the number equal to the number of nodes.

But I want to label the nodes with different numbers from a list.

Lets say ID is a list of numbers. and the labels should be taken from this list.

How can I do it?

$\endgroup$
3
$\begingroup$

With

ids = RandomChoice[CharacterRange["a", "z"], VertexCount[G]];

use the option

VertexLabels -> {v_ :> Placed[Style[ids[[v]], White], Center]

in Graph[...].

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.