@@ -18,41 +18,41 @@ From the Julia REPL the latest version can be installed with
18
18
Pkg.add("GraphPlot")
19
19
```
20
20
GraphPlot is then loaded with
21
- ```
21
+ ``` julia
22
22
using GraphPlot
23
23
```
24
24
25
25
# Usage
26
26
## karate network
27
- ```
27
+ ``` julia
28
28
g = graphfamous (" karate" )
29
29
gplot (g)
30
30
31
31
```
32
32
33
33
## Add node label
34
- ```
34
+ ``` julia
35
35
using Graphs
36
36
nodelabel = [1 : num_vertices (g)]
37
37
gplot (g, nodelabel= nodelabel)
38
38
39
39
```
40
40
41
41
## Adjust node labels
42
- ```
42
+ ``` julia
43
43
gplot (g, nodelabel= nodelabel, nodelabeldist= 1.5 , nodelabelangleoffset= π/ 4 )
44
44
```
45
45
46
46
## Control the node size
47
- ```
47
+ ``` julia
48
48
# nodes size proportional to their degree
49
49
nodesize = [Graphs. out_degree (v, g) for v in Graphs. vertices (g)]
50
50
gplot (g, nodesize= nodesize)
51
51
```
52
52
53
53
## Control the node color
54
54
Feed the keyword argument ` nodefillc ` a color array, ensure each node has a color. ` length(nodefillc) ` must be equal ` |V| ` .
55
- ```
55
+ ``` julia
56
56
using Colors
57
57
58
58
# Generate n maximally distinguishable colors in LCHab space.
@@ -61,32 +61,32 @@ gplot(g, nodefillc=nodefillc, nodelabel=nodelabel, nodelabeldist=1.8, nodelabela
61
61
```
62
62
63
63
## Transparent
64
- ```
64
+ ``` julia
65
65
# stick out large degree nodes
66
66
alphas = nodesize/ maximum (nodesize)
67
67
nodefillc = [RGBA (0.0 ,0.8 ,0.8 ,i) for i in alphas]
68
68
gplot (g, nodefillc= nodefillc)
69
69
```
70
70
## Control the node label size
71
- ```
71
+ ``` julia
72
72
nodelabelsize = nodesize
73
73
gplot (g, nodelabelsize= nodelabelsize, nodesize= nodesize, nodelabel= nodelabel)
74
74
```
75
75
76
76
## Draw edge labels
77
- ```
77
+ ``` julia
78
78
edgelabel = [1 : Graphs. num_edges (g)]
79
79
gplot (g, edgelabel= edgelabel, nodelabel= nodelabel)
80
80
```
81
81
82
82
## Adjust edge labels
83
- ```
83
+ ``` julia
84
84
edgelabel = [1 : Graphs. num_edges (g)]
85
85
gplot (g, edgelabel= edgelabel, nodelabel= nodelabel, edgelabeldistx= 0.5 , edgelabeldisty= 0.5 )
86
86
```
87
87
88
88
## Color the graph
89
- ```
89
+ ``` julia
90
90
# nodes membership
91
91
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 ]
92
92
nodecolor = [colorant " lightseagreen" , colorant " orange" ]
@@ -97,19 +97,19 @@ gplot(g, nodefillc=nodefillc)
97
97
98
98
## Different layout
99
99
### random layout
100
- ```
100
+ ``` julia
101
101
gplot (g, layout= random_layout, nodelabel= nodelabel)
102
102
```
103
103
### circular layout
104
- ```
104
+ ``` julia
105
105
gplot (g, layout= circular_layout, nodelabel= nodelabel)
106
106
```
107
107
### spectral layout
108
- ```
108
+ ``` julia
109
109
gplot (g, layout= spectral_layout)
110
110
```
111
111
### shell layout
112
- ```
112
+ ``` julia
113
113
nlist = Array (Vector{Int}, 2 ) # two shells
114
114
nlist[1 ] = [1 : 5 ] # first shell
115
115
nlist[2 ] = [6 : num_vertices (g)] # second shell
@@ -118,7 +118,7 @@ gplot(g, locs_x, locs_y, nodelabel=nodelabel)
118
118
```
119
119
120
120
## Curve edge
121
- ```
121
+ ``` julia
122
122
gplot (g, linetype= " curve" )
123
123
```
124
124
@@ -133,7 +133,7 @@ draw(PNG("karate.png", 16cm, 16cm), gplot(g))
133
133
draw(SVG("karate.svg", 16cm, 16cm), gplot(g))
134
134
```
135
135
# LightGraphs integration
136
- ```
136
+ ``` julia
137
137
using LightGraphs
138
138
h = watts_strogatz (50 , 6 , 0.3 )
139
139
gplot (h)
@@ -157,4 +157,3 @@ Set to 0 for no arrows. Default: 0 for undirected graph and 0.1 for directed gra
157
157
# Reporting Bugs
158
158
159
159
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.
160
-
0 commit comments