1
$\begingroup$

I have the adjacency matrix of graph and I want visualize this graph. I tried:

AdjacencyGraph[{v1,v2,v3,v4,v5,v6,v7,v8,v9,v10}, {{0,0,0,1,0,1,1,1,0,0}, {0,0,0,0,0,1,1,1,1,1}, {0,0,0,0,0,0,0,1,1,0}, {1,0,0,0,0,0,0,1,0,0}, {0,0,0,0,0,1,0,1,0,0}, {1,1,0,0,1,0,1,0,1,1}, {1,1,0,0,0,1,0,0,0,1}, {1,1,1,1,1,0,0,0,0,1}, {0,1,1,0,0,1,0,0,0,0}, {0,1,0,0,0,1,1,1,0,0}}] 

and

AdjacencyGraph[ {{0,0,0,1,0,1,1,1,0,0}, {0,0,0,0,0,1,1,1,1,1}, {0,0,0,0,0,0,0,1,1,0}, {1,0,0,0,0,0,0,1,0,0}, {0,0,0,0,0,1,0,1,0,0}, {1,1,0,0,1,0,1,0,1,1}, {1,1,0,0,0,1,0,0,0,1}, {1,1,1,1,1,0,0,0,0,1}, {0,1,1,0,0,1,0,0,0,0}, {0,1,0,0,0,1,1,1,0,0}}] 

Output is:

enter image description here

How to add names of vertices to graph?

$\endgroup$

4 Answers 4

2
$\begingroup$

VertexLabelsdoes the job.

AdjacencyGraph[{ {0, 0, 0, 1, 0, 1, 1, 1, 0, 0}, {0, 0, 0, 0, 0, 1, 1, 1, 1, 1}, {0, 0, 0, 0, 0, 0, 0, 1, 1, 0}, {1, 0, 0, 0, 0, 0, 0, 1, 0, 0}, {0, 0, 0, 0, 0, 1, 0, 1, 0, 0}, {1, 1, 0, 0, 1, 0, 1, 0, 1, 1}, {1, 1, 0, 0, 0, 1, 0, 0, 0, 1}, {1, 1, 1, 1, 1, 0, 0, 0, 0, 1}, {0, 1, 1, 0, 0, 1, 0, 0, 0, 0}, {0, 1, 0, 0, 0, 1, 1, 1, 0, 0}}, VertexLabels -> Table[i -> Subscript[v, i], {i, 10}]] 

enter image description here

$\endgroup$
3
$\begingroup$

Similarily to the above:

Code:

g = {{0, 0, 0, 1, 0, 1, 1, 1, 0, 0}, {0, 0, 0, 0, 0, 1, 1, 1, 1, 1}, {0, 0, 0, 0, 0, 0, 0, 1, 1, 0}, {1, 0, 0, 0, 0, 0, 0, 1, 0, 0}, {0, 0, 0, 0, 0, 1, 0, 1, 0, 0}, {1, 1, 0, 0, 1, 0, 1, 0, 1, 1}, {1, 1, 0, 0, 0, 1, 0, 0, 0, 1}, {1, 1, 1, 1, 1, 0, 0, 0, 0, 1}, {0, 1, 1, 0, 0, 1, 0, 0, 0, 0}, {0, 1, 0, 0, 0, 1, 1, 1, 0, 0}}; AdjacencyGraph[g, VertexLabels -> "Name"] 

Output:

Adjacency graph v.1

$\endgroup$
1
$\begingroup$
AdjacencyGraph[ {Labeled[v1, "1"], Labeled[v2, "2"], Labeled[v3, "3"], Labeled[v4, "4"], Labeled[v5, "5"], Labeled[v6, "6"], Labeled[v7, "7"], Labeled[v8, "8"], Labeled[v9, "9"], Labeled[v10, "10"]}, {{0,0,0,1,0,1,1,1,0,0}, {0,0,0,0,0,1,1,1,1,1}, {0,0,0,0,0,0,0,1,1,0}, {1,0,0,0,0,0,0,1,0,0}, {0,0,0,0,0,1,0,1,0,0}, {1,1,0,0,1,0,1,0,1,1}, {1,1,0,0,0,1,0,0,0,1}, {1,1,1,1,1,0,0,0,0,1}, {0,1,1,0,0,1,0,0,0,0}, {0,1,0,0,0,1,1,1,0,0}}] 

enter image description here

$\endgroup$
1
$\begingroup$

Add VertexLabels -> "Name" to your first command.

AdjacencyGraph[{v1,v2,v3,v4,v5,v6,v7,v8,v9,v10}, {{0,0,0,1,0,1,1,1,0,0}, {0,0,0,0,0,1,1,1,1,1}, {0,0,0,0,0,0,0,1,1,0}, {1,0,0,0,0,0,0,1,0,0}, {0,0,0,0,0,1,0,1,0,0}, {1,1,0,0,1,0,1,0,1,1}, {1,1,0,0,0,1,0,0,0,1}, {1,1,1,1,1,0,0,0,0,1}, {0,1,1,0,0,1,0,0,0,0}, {0,1,0,0,0,1,1,1,0,0}}, VertexLabels -> "Name"] 

enter image description here

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.