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]:
5x5 Array{Bool,2}:
 false   true   true  false  false
 false  false   true   true  false
 false  false  false  false   true
 false  false  false  false  false
 false  false  false  false  false

In [4]:
x, y = GraphLayout.layout_spring_adj(am)


Out[4]:
([0.052086460387572364,-0.3342146774168322,0.3672453741159285,-1.0,1.0],[1.0,-0.16601740453784009,-0.33155139142758694,-0.5332447092524314,-1.0])

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]:
graph_edge_lists (generic function with 1 method)

In [10]:
edgex, edgey = graph_edge_lists(x, y)


Out[10]:
([0.052086460387572364,-0.3342146774168322,NaN,0.052086460387572364,0.3672453741159285,NaN,-0.3342146774168322,0.3672453741159285,NaN,-0.3342146774168322,-1.0,NaN,0.3672453741159285,1.0,NaN],[1.0,-0.16601740453784009,NaN,1.0,-0.33155139142758694,NaN,-0.16601740453784009,-0.33155139142758694,NaN,-0.16601740453784009,-0.5332447092524314,NaN,-0.33155139142758694,-1.0,NaN])

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)


[Plots.jl] Initializing backend: pyplot
n = 4
source = [1,2,2,3,4]
destiny = [2,3,4,4,1]
weights = 1.0:1.0:5.0
x = [0.45704230658906037,0.619705900077711,2.151693446660977,-2.3558319986163956]
y = [3.0,1.0,3.0,1.0]
z = nothing
weights = 1.0:1.0:5.0
INFO: converged. numiter=10 last=1.0132016233513697 this=1.0132515284545873
Out[1]:
lz = [1.0,2.0,3.0,4.0,5.0]
/home/tom/.julia/v0.4/Conda/deps/usr/lib/python2.7/site-packages/matplotlib/font_manager.py:1288: UserWarning: findfont: Font family [u'Helvetica'] not found. Falling back to Bitstream Vera Sans
  (prop.get_family(), self.defaultFamily[fontext]))

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]:
5

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


outdeg = [4,1,2,2,2,2,1,2,1,2]
indeg = [0,1,1,4,2,3,3,2,0,3]
netdeg = [4,-4,-3,-18,-8,-13,-14,-8,1,-13]
idxs = [1,9,3,2,5,8,6,10,7,4]
INFO: converged. numiter=63 last=0.27069980016830764 this=0.27072601605547214
Out[3]:
- 8 - 6 - 4 - 2 0 - 2 0 2 1 2 3 4 5 6 7 8 9 10

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)


dist = [0.0 1.0 2.0 2.0 3.0 3.0 2.0
 1.0 0.0 1.0 1.0 2.0 2.0 1.0
 2.0 1.0 0.0 2.0 1.0 1.0 2.0
 2.0 1.0 2.0 0.0 1.0 2.0 1.0
 3.0 2.0 1.0 1.0 0.0 1.0 2.0
 3.0 2.0 1.0 2.0 1.0 0.0 3.0
 2.0 1.0 2.0 1.0 2.0 3.0 0.0]
INFO: converged. numiter=78 last=8.36881038844636e-6 this=8.36959291080617e-6
Out[3]:
- 4 - 2 0 0 0.5 1.0 1 2 3 4 5 6 7

In [4]:
png("/tmp/tmp")

In [ ]: