The setup.jl
script that we include below does a few things to install
packages that we will need including the MatrixNetworks.jl
package that
Huda Nassar has been building to make working with graphs easy in Julia
(in a way that interoperates with matrix operations).
It also configures a few plotting packages PyPlot
and Gadfly
In [5]:
include("setup.jl")
Now we are going to test the packages themselves to make sure things are working. If this step fails, many of the other ideas will not work either.
In [3]:
using MatrixNetworks
using PyPlot
using Gadfly
using Compose
using Interact
In [4]:
PyPlot.plot(randn(50))
Out[4]:
In [5]:
# E.g.
Gadfly.plot(x=collect(1:100), y=sort(rand(100)))
Out[5]:
In [9]:
@manipulate for phi=0:pi/16:4*pi
Gadfly.plot(x -> sin(x + phi), 0, 25)
end
Out[9]:
In [14]:
matrix_network_datasets()
(A,xy) = load_matrix_network_metadata("bfs_example")
Out[14]:
In [120]:
function graphplot(A,xy)
(ei,ej) = findnz(triu(A))
lx = [xy[ei,1]';xy[ej,1]';NaN*ones(1,length(ei))]
ly = [xy[ei,2]';xy[ej,2]';NaN*ones(1,length(ei))]
lines = PyPlot.plot(lx,ly)
PyPlot.axis("off")
PyPlot.setp(lines,alpha=0.5,color=[0.,0.,0.],zorder=0)
end
graphplot(A,xy)
PyPlot.scatter(xy[:,1],xy[:,2],25*rand(size(A,1)),edgecolors="none",zorder=2)
Out[120]:
In [127]:
(A,xy) = load_matrix_network_metadata("airports")
graphplot(A,xy)
PyPlot.scatter(xy[:,1],xy[:,2],25*rand(size(A,1)),edgecolors="none",zorder=2)
Out[127]:
In [82]:
(ei,ej) = findnz(triu(A))
glines = [ [(xy[ei[i],1],xy[ei[i],2]), (xy[ej[i],1],xy[ej[i],2])]
for i=1:length(ei)]'
#glines = Vector{Vector{Tuple{Float64,Float64}}}()
@show glines
@show typeof(glines)
compose(context(), line(glines), stroke("black"))
#compose(context(), line([[(0,0), (1,1)]; [(0,1), (1,0)]]), stroke("black"))
Out[82]:
In [123]:
using Gadfly,Reactive,Interact,PyPlot
myfig = figure()
function myplot(data)
withfig(myfig) do
PyPlot.plot(data[1], data[2])
axis([0,1,-.3,.3])
end
end
x = collect(linspace(0,1,100))
myinput=Input((x,0*x))
lift(myplot, myinput)
Out[123]:
In [125]:
x = collect(linspace(0,1,100))
for t = -1:.1:1
y = t * x .*(1-x)
push!(myinput,(x, y))
sleep(0.25)
end
In [99]:
using Gadfly,Reactive,Interact
function myplot2(data)
Gadfly.plot(x=data[1], y=data[2])
end
x = collect(linspace(0,1,100))
myinput=Input((x,0*x))
lift(myplot2, myinput)
Out[99]:
In [100]:
x = collect(linspace(0,1,100))
for t = -1:.1:1
y = t * x .*(1-x)
push!(myinput,(x, y))
end