• Stars
    star
    200
  • Rank 195,396 (Top 4 %)
  • Language
    Julia
  • License
    Other
  • Created about 9 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Graph visualization for Julia.

GraphPlot

CI version

Graph layout and visualization algorithms based on Compose.jl and inspired by GraphLayout.jl.

The spring_layout and stressmajorize_layout function are copy from IainNZ's GraphLayout.jl.

Other layout algorithms are wrapped from NetworkX.

gadfly.js is copied from Gadfly.jl

Getting Started

From the Julia REPL the latest version can be installed with

Pkg.add("GraphPlot")

GraphPlot is then loaded with

using GraphPlot

Usage

karate network

using Graphs: smallgraph
g = smallgraph(:karate)
gplot(g)

Add node label

using Graphs
nodelabel = 1:nv(g)
gplot(g, nodelabel=nodelabel)

Adjust node labels

gplot(g, nodelabel=nodelabel, nodelabeldist=1.5, nodelabelangleoffset=Ï€/4)

Control the node size

# nodes size proportional to their degree
nodesize = [Graphs.outdegree(g, v) for v in Graphs.vertices(g)]
gplot(g, nodesize=nodesize)

Control the node color

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(nv(g), colorant"blue")
gplot(g, nodefillc=nodefillc, nodelabel=nodelabel, nodelabeldist=1.8, nodelabelangleoffset=Ï€/4)

Transparent

# 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)

Control the node label size

nodelabelsize = nodesize
gplot(g, nodelabelsize=nodelabelsize, nodesize=nodesize, nodelabel=nodelabel)

Draw edge labels

edgelabel = 1:Graphs.ne(g)
gplot(g, edgelabel=edgelabel, nodelabel=nodelabel)

Adjust edge labels

edgelabel = 1:Graphs.ne(g)
gplot(g, edgelabel=edgelabel, nodelabel=nodelabel, edgelabeldistx=0.5, edgelabeldisty=0.5)

Color the graph

# 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)

Different layout

spring layout (default)

This is the defaut layout and will be chosen if no layout is specified. The default parameters to the spring layout algorithm can be changed by supplying an anonymous function, e.g., if nodes appear clustered too tightly together, try

layout=(args...)->spring_layout(args...; C=20)
gplot(g, layout=layout, nodelabel=nodelabel)

where C influences the desired distance between nodes.

random layout

gplot(g, layout=random_layout, nodelabel=nodelabel)

circular layout

gplot(g, layout=circular_layout, nodelabel=nodelabel)

spectral layout

gplot(g, layout=spectral_layout)

shell layout

nlist = Vector{Vector{Int}}(undef, 2) # two shells
nlist[1] = 1:5 # first shell
nlist[2] = 6:nv(g) # second shell
locs_x, locs_y = shell_layout(g, nlist)
gplot(g, locs_x, locs_y, nodelabel=nodelabel)

Curve edge

gplot(g, linetype="curve")

Show plot

When using an IDE such as VSCode, Cairo.jl is required to visualize the plot inside the IDE. When using the REPL, gplothtml will allow displaying the plot on a browser.

Save to figure

using Compose
# save to pdf
draw(PDF("karate.pdf", 16cm, 16cm), gplot(g))
# save to png
draw(PNG("karate.png", 16cm, 16cm), gplot(g))
# save to svg
draw(SVG("karate.svg", 16cm, 16cm), gplot(g))

Graphs.jl integration

using Graphs
h = watts_strogatz(50, 6, 0.3)
gplot(h)

Arguments

  • G Graph to draw
  • locs_x, locs_y Locations of the nodes (will be normalized and centered). If not specified, will be obtained from layout kwarg.

Keyword Arguments

  • layout Layout algorithm: random_layout, circular_layout, spring_layout, shell_layout, stressmajorize_layout, spectral_layout. Default: spring_layout
  • NODESIZE Max size for the nodes. Default: 3.0/sqrt(N)
  • nodesize Relative size for the nodes, can be a Vector. Default: 1.0
  • nodelabel Labels for the vertices, a Vector or nothing. Default: nothing
  • nodelabelc Color for the node labels, can be a Vector. Default: colorant"black"
  • nodelabeldist Distances for the node labels from center of nodes. Default: 0.0
  • nodelabelangleoffset Angle offset for the node labels. Default: Ï€/4.0
  • NODELABELSIZE Largest fontsize for the vertice labels. Default: 4.0
  • nodelabelsize Relative fontsize for the vertice labels, can be a Vector. Default: 1.0
  • nodefillc Color to fill the nodes with, can be a Vector. Default: colorant"turquoise"
  • nodestrokec Color for the nodes stroke, can be a Vector. Default: nothing
  • nodestrokelw Line width for the nodes stroke, can be a Vector. Default: 0.0
  • edgelabel Labels for the edges, a Vector or nothing. Default: []
  • edgelabelc Color for the edge labels, can be a Vector. Default: colorant"black"
  • edgelabeldistx, edgelabeldisty Distance for the edge label from center of edge. Default: 0.0
  • EDGELABELSIZE Largest fontsize for the edge labels. Default: 4.0
  • edgelabelsize Relative fontsize for the edge labels, can be a Vector. Default: 1.0
  • EDGELINEWIDTH Max line width for the edges. Default: 0.25/sqrt(N)
  • edgelinewidth Relative line width for the edges, can be a Vector. Default: 1.0
  • edgestrokec Color for the edge strokes, can be a Vector. Default: colorant"lightgray"
  • arrowlengthfrac Fraction of line length to use for arrows. Equal to 0 for undirected graphs. Default: 0.1 for the directed graphs
  • arrowangleoffset Angular width in radians for the arrows. Default: Ï€/9 (20 degrees)
  • linetype Type of line used for edges ("straight", "curve"). Default: "straight"
  • outangle Angular width in radians for the edges (only used if linetype = "curve). Default: Ï€/5 (36 degrees)

Reporting Bugs

Filing an issue to report a bug, counterintuitive behavior, or even to request a feature is extremely valuable in helping me prioritize what to work on, so don't hestitate.

More Repositories

1

Graphs.jl

An optimized graphs package for the Julia programming language
Julia
451
star
2

MultilayerGraphs.jl

A Julia package for the creation, manipulation and analysis of the structure, dynamics and functions of multilayer graphs.
Julia
117
star
3

MatrixNetworks.jl

Graph and Network algorithms in Julia
Julia
109
star
4

JuliaGraphsTutorials

Tutorials in the form of Jupyter notebooks for the JuliaGraphs ecosystem
Jupyter Notebook
97
star
5

NetworkLayout.jl

Layout algorithms for graphs and trees in pure Julia.
Julia
96
star
6

MetaGraphsNext.jl

A package for graphs with vertex labels and metadata in Julia
Julia
73
star
7

GraphViz.jl

Julia Binding to the GraphViz library
Julia
67
star
8

GraphIO.jl

Graph IO functionality for various formats.
Julia
61
star
9

MetaGraphs.jl

Graph data structures with multiple heterogeneous metadata for Graphs.jl.
Julia
58
star
10

SimpleWeightedGraphs.jl

Edge-weighted graphs compatible with Graphs.jl
Julia
37
star
11

LightGraphsFlows.jl

Flow algorithms on LightGraphs
Julia
36
star
12

StaticGraphs.jl

Memory-efficient immutable LightGraphs.
Julia
32
star
13

GraphDataFrameBridge.jl

Tools for interoperability between DataFrame objects and LightGraphs and MetaGraphs objects
Julia
30
star
14

GraphsFlows.jl

Flow algorithms on Graphs.jl
Julia
27
star
15

LightGraphsExtras.jl

Additional functionality for LightGraphs.jl
Julia
21
star
16

GraphsOptim.jl

A package for graph optimization algorithms that rely on mathematical programming.
Julia
17
star
17

VegaGraphs.jl

Create beatiful and interactive visualizations for graphs using Vega-Lite
Jupyter Notebook
16
star
18

SNAPDatasets.jl

LightGraphs.jl-formatted graph files taken from the SNAP Datasets collection.
Julia
16
star
19

GraphsMatching.jl

Matching algorithms for Graphs.jl
Julia
15
star
20

CommunityDetection.jl

Community Detection algorithms for LightGraphs
Julia
14
star
21

LightGraphsMatching.jl

Matching algorithms for LightGraphs.jl
Julia
13
star
22

GraphsBase.jl

Basic interface and structures for the JuliaGraphs ecosystem
Julia
11
star
23

SpecialGraphs.jl

Encoding special graph structures in types
Julia
8
star
24

juliagraphs.github.io

Organization page
SCSS
7
star
25

JuliaGraphs-meta

Forum for JuliaGraphs discussion - issues only.
6
star
26

GraphsExtras.jl

Additional functionality for Graphs.jl
Julia
5
star
27

BlossomMatching.jl

A Julia implementation of the Blossom V matching algorithm
Julia
5
star
28

Graph500.jl

Graph500 benchmarks written in Julia using LightGraphs
Julia
4
star
29

D3GraphPlot.jl

Julia
4
star
30

GraphCentrality.jl

(DEPRECATED) Centrality measures for Graphs.jl
Julia
4
star
31

DBGraphs.jl

Julia
3
star
32

Networks.jl

(DEPRECATED) Additional graph flexibility for LightGraphs
Julia
3
star
33

GraphsInterfaceChecker.jl

Formalization of the AbstractGraph interface from Graphs.jl, specified using Interfaces.jl.
Julia
3
star