In [ ]:
Pkg.add("Graphs")
Pkg.add("GraphLayout")
In [12]:
using Plots
pyplot(size=(500,300))
import Graphs, GraphLayout
In [13]:
n = 5
g = Graphs.simple_graph(n)
for (i,j) in [(1,2),(2,3),(1,3),(2,4),(3,5)]
Graphs.add_edge!(g, i, j)
end
In [14]:
am = Graphs.adjacency_matrix(g)
Out[14]:
In [4]:
x, y = GraphLayout.layout_spring_adj(am)
Out[4]:
In [5]:
function graph_edge_lists(x, y)
edgex, edgey = zeros(0), zeros(0)
for i=1:n, j=1:n
if am[i,j]
append!(edgex, [x[i], x[j], NaN])
append!(edgey, [y[i], y[j], NaN])
end
end
edgex, edgey
end
Out[5]:
In [10]:
edgex, edgey = graph_edge_lists(x, y)
Out[10]:
In [11]:
with(leg=:best, grid=false) do
plot(edgex, edgey, lab="edges")
scatter!(x, y, m=20, lab="nodes", ann=map(text,1:n))
end
Out[11]:
In [ ]: