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 [ ]:
In [ ]:
In [1]:
using PlotRecipes; pyplot()
s = [1,2,2,3,4]
d = [2,3,4,4,1]
w = 1.:length(s)
n = max(maximum(s), maximum(d))
graphplot(s,d,w, m=(linspace(20,40,n),:greens), l=(4,:blues), series_annotations=map(string,1:n), func=:tree)
Out[1]:
In [ ]:
In [22]:
using PlotRecipes; pyplot(size=(300,300))
s = [1,2,2,3,4,5]
d = [2,3,4,4,5,1]
w = 1.:length(s)
# w = ones(length(s))
n = max(maximum(s), maximum(d))
Out[22]:
In [3]:
using PlotRecipes; gr(size=(500,500))
n = 10
s, d = Plots.unzip(unique([(rand(1:n),rand(1:n)) for i=1:20]))
s = convert(Vector{Int}, s)
d = convert(Vector{Int}, d)
w = 4ones(length(s));
basex, basey = rand(n), rand(n)
# x, y = PlotRecipes.tree_graph(s,d,w, x=copy(basex),y=copy(basey),maxiter=10)
# graphplot(s,d,w,func=:tree,direction=:left,series_annotations=map(string,1:n))
layers = rand(1:4, n)
@gif for i=1:50
x, y = PlotRecipes.tree_graph(s,d,w, x=copy(basex),y=copy(basey),maxiter=i,layers=layers)
graphplot(s,d,w, m=(linspace(20,40,n),:inferno), l=(3,:black), x=x, y=y, series_annotations=map(string,1:n), curves=false)
end
Out[3]:
In [ ]:
In [3]:
using PlotRecipes; gr(size=(500,500))
s = [1,2,2,3,3,2,5,4,7]
d = [2,3,4,5,6,7,6,5,4]
w = ones(length(s))
n = max(maximum(s), maximum(d))
graphplot(s,d,w,func=:tree,series_annotations=map(string,1:n),root=:top)
Out[3]:
In [4]:
png("/tmp/tmp")
In [ ]: