How to plot a graph of an adjacency matrix

I am trying, without success, to plot a graph based on an adjacency matrix and using the Graphs.jl and GraphPlot.jl packages.

What am I doing wrong?

graph = [
          [0, 2, 4, 0, 0, 0],
          [0, 0, 1, 7, 0, 0],
          [0, 0, 0, 0, 3, 0],
          [0, 0, 0, 0, 0, 1],
          [0, 0, 0, 2, 0, 5],
          [0, 0, 0, 0, 0, 0],
        ];

using Graphs
using GraphPlot

g = SimpleGraph(graph)
gplot(g)

A symmetric adjacency matrix like this can be used to create an undirected graph:

graph = [0 1 1 0 0;
         1 0 0 1 0;
         1 0 0 1 1;
         0 1 1 0 1;
         0 0 1 1 0]

To draw your (asymmetric) matrix, use a directed graph:

graph = [
    0  2  4  0  0  0 ; 
    0  0  1  7  0  0 ;
    0  0  0  0  3  0 ;
    0  0  0  0  0  1 ;
    0  0  0  2  0  5 ;
    0  0  0  0  0  0 ]

g = SimpleDiGraph(graph)
2 Likes