Plotting and visualization of graphs (networks)
From the Julia REPL the latest version can be installed with
Pkg.clone("git://github.com/afternone/GraphPlot.jl.git")
GraphPlot is then loaded with
using GraphPlot
g = graphfamous("karate")
gplot(g)
using Graphs
nodelabel = [1:num_vertices(g)]
gplot(g, nodelabel=nodelabel)
gplot(g, nodelabel=nodelabel, nodelabeldist=1.5, nodelabelangleoffset=Ï€/4)
# nodes size proportional to their degree
nodesize = [Graphs.out_degree(v, g) for v in Graphs.vertices(g)]
gplot(g, nodesize=nodesize)
Feed the keyword argument nodefillc
a color array, ensure each node has a color. length(nodefillc)
must be equal |V|
.
using Colors
# Generate n maximally distinguishable colors in LCHab space.
nodefillc = distinguishable_colors(num_vertices(g), colorant"blue")
gplot(g, nodefillc=nodefillc, nodelabel=nodelabel, nodelabeldist=1.8, nodelabelangleoffset=Ï€/4)
# stick out large degree nodes
alphas = nodesize/maximum(nodesize)
nodefillc = [RGBA(0.0,0.8,0.8,i) for i in alphas]
gplot(g, nodefillc=nodefillc)
nodelabelsize = nodesize
gplot(g, nodelabelsize=nodelabelsize, nodesize=nodesize, nodelabel=nodelabel)
edgelabel = [1:Graphs.num_edges(g)]
gplot(g, edgelabel=edgelabel, nodelabel=nodelabel)
edgelabel = [1:Graphs.num_edges(g)]
gplot(g, edgelabel=edgelabel, nodelabel=nodelabel, edgelabeldistx=0.5, edgelabeldisty=0.5)
# nodes membership
membership = [1,1,1,1,1,1,1,1,2,1,1,1,1,1,2,2,1,1,2,1,2,1,2,2,2,2,2,2,2,2,2,2,2,2]
nodecolor = [colorant"lightseagreen", colorant"orange"]
# membership color
nodefillc = nodecolor[membership]
gplot(g, nodefillc=nodefillc)
gplot(g, layout=random_layout, nodelabel=nodelabel)
gplot(g, layout=circular_layout, nodelabel=nodelabel)