Skip to content

Commit 329ee53

Browse files
blegatsbromberger
authored andcommitted
Add color syntaxing in README (#53)
1 parent 02800ca commit 329ee53

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

README.md

+17-18
Original file line numberDiff line numberDiff line change
@@ -18,41 +18,41 @@ From the Julia REPL the latest version can be installed with
1818
Pkg.add("GraphPlot")
1919
```
2020
GraphPlot is then loaded with
21-
```
21+
```julia
2222
using GraphPlot
2323
```
2424

2525
# Usage
2626
## karate network
27-
```
27+
```julia
2828
g = graphfamous("karate")
2929
gplot(g)
3030

3131
```
3232

3333
## Add node label
34-
```
34+
```julia
3535
using Graphs
3636
nodelabel = [1:num_vertices(g)]
3737
gplot(g, nodelabel=nodelabel)
3838

3939
```
4040

4141
## Adjust node labels
42-
```
42+
```julia
4343
gplot(g, nodelabel=nodelabel, nodelabeldist=1.5, nodelabelangleoffset=π/4)
4444
```
4545

4646
## Control the node size
47-
```
47+
```julia
4848
# nodes size proportional to their degree
4949
nodesize = [Graphs.out_degree(v, g) for v in Graphs.vertices(g)]
5050
gplot(g, nodesize=nodesize)
5151
```
5252

5353
## Control the node color
5454
Feed the keyword argument `nodefillc` a color array, ensure each node has a color. `length(nodefillc)` must be equal `|V|`.
55-
```
55+
```julia
5656
using Colors
5757

5858
# Generate n maximally distinguishable colors in LCHab space.
@@ -61,32 +61,32 @@ gplot(g, nodefillc=nodefillc, nodelabel=nodelabel, nodelabeldist=1.8, nodelabela
6161
```
6262

6363
## Transparent
64-
```
64+
```julia
6565
# stick out large degree nodes
6666
alphas = nodesize/maximum(nodesize)
6767
nodefillc = [RGBA(0.0,0.8,0.8,i) for i in alphas]
6868
gplot(g, nodefillc=nodefillc)
6969
```
7070
## Control the node label size
71-
```
71+
```julia
7272
nodelabelsize = nodesize
7373
gplot(g, nodelabelsize=nodelabelsize, nodesize=nodesize, nodelabel=nodelabel)
7474
```
7575

7676
## Draw edge labels
77-
```
77+
```julia
7878
edgelabel = [1:Graphs.num_edges(g)]
7979
gplot(g, edgelabel=edgelabel, nodelabel=nodelabel)
8080
```
8181

8282
## Adjust edge labels
83-
```
83+
```julia
8484
edgelabel = [1:Graphs.num_edges(g)]
8585
gplot(g, edgelabel=edgelabel, nodelabel=nodelabel, edgelabeldistx=0.5, edgelabeldisty=0.5)
8686
```
8787

8888
## Color the graph
89-
```
89+
```julia
9090
# nodes membership
9191
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]
9292
nodecolor = [colorant"lightseagreen", colorant"orange"]
@@ -97,19 +97,19 @@ gplot(g, nodefillc=nodefillc)
9797

9898
## Different layout
9999
### random layout
100-
```
100+
```julia
101101
gplot(g, layout=random_layout, nodelabel=nodelabel)
102102
```
103103
### circular layout
104-
```
104+
```julia
105105
gplot(g, layout=circular_layout, nodelabel=nodelabel)
106106
```
107107
### spectral layout
108-
```
108+
```julia
109109
gplot(g, layout=spectral_layout)
110110
```
111111
### shell layout
112-
```
112+
```julia
113113
nlist = Array(Vector{Int}, 2) # two shells
114114
nlist[1] = [1:5] # first shell
115115
nlist[2] = [6:num_vertices(g)] # second shell
@@ -118,7 +118,7 @@ gplot(g, locs_x, locs_y, nodelabel=nodelabel)
118118
```
119119

120120
## Curve edge
121-
```
121+
```julia
122122
gplot(g, linetype="curve")
123123
```
124124

@@ -133,7 +133,7 @@ draw(PNG("karate.png", 16cm, 16cm), gplot(g))
133133
draw(SVG("karate.svg", 16cm, 16cm), gplot(g))
134134
```
135135
# LightGraphs integration
136-
```
136+
```julia
137137
using LightGraphs
138138
h = watts_strogatz(50, 6, 0.3)
139139
gplot(h)
@@ -157,4 +157,3 @@ Set to 0 for no arrows. Default: 0 for undirected graph and 0.1 for directed gra
157157
# Reporting Bugs
158158

159159
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

Comments
 (0)