Third-party implementations of scripting for Gephi:
The code numbers.py is listed below:
#!/usr/bin/env python
numberOfGroups = 15 # the number of nodes is (numberOfGroups+1)**2-1
numberOfLongConnections = 100 # number of completely random long edges
# network contribution #1: almost isolated communities
numberOfNodes = (numberOfGroups+1)**2 - 1
from random import choice
for i in range(1,numberOfGroups+1):
square = i**2
nextSquare = (i+1)**2
print(i,';',square,sep='')
for j in range(square,nextSquare):
group = list(range(square,nextSquare))
group.remove(j)
a1 = choice(group)
group.remove(a1)
a2 = choice(group)
group.remove(a2)
print(j,';',a1,';',a2,sep='')
# network contribution #2: completely random long edges
if numberOfLongConnections > 0:
allPoints = list(range(1,numberOfNodes))
for i in range(numberOfLongConnections):
a = choice(allPoints)
allPoints.remove(a)
b = choice(allPoints)
allPoints.remove(b)
print(a,';',b,sep='')
Let’s try numberOfGroups = 6 and numberOfLongConnections = 0. This will give us (numberOfGroups+1)**2-1 = 48 nodes and 102 edges.
$ ./numbers.py > numbers.csv
Let’s open this file in Gephi and walk through its GUI: Overview, Data Laboratory, Statistics, Context.
Fruchterman-Reingold force-directed layout (more space within a decided area)
ForceAtlas2 force-directed layout (disperse groups with space around larger nodes)
In Overview -> Statistics panel compute Eigenvalue Centrality. In Data Laboratory -> Data Table for nodes see the new column Eigenvalue Centrality. In Overview -> Appearance panel colour nodes (Nodes + Color + Attribute) colour nodes by Eigenvalue Centrality with a reverse colour map (smaller circles in dark, to make them more visible).
In Overview -> Statistics panel compute Modularity with resoluton=1. In Overview -> Appearance panel set Nodes + Colour + Attribute to Modularity Class. The dataset is now coloured by the group, with ~5 groups (communities). Lower resolution=0.5 produces more groups.
Let’s rebuilt our graph with numberOfGroups = 15 and numberOfLongConnections = 0. This will produce 255 nodes and 525 edges. Run Layout -> Force Atlas 2.
Let’s rebuilt our graph with numberOfGroups = 15 and numberOfLongConnections = 100. This will produce 255 nodes and 625 edges. Run Layout -> Force Atlas 2.
Preview -> Refresh and then save as PNG at 2000x2000. Now add labels.
In Overview bring up a Window -> Filters panel.
Let’s rebuilt our graph with numberOfGroups = 50 and numberOfLongConnections = 300. This will produce 2600 nodes and 5550 edges.
We can also generate graphs with File -> Generate -> Random Graph. Try 1000 nodes and 0.01 wiring probability.
NumberOfGroups = 300 and numberOfLongConnections = 1000. This will produce 90,600 nodes and 182,500 edges. Takes few minutes to converge on my laptop.
We will look at a geographical network of 1000 individuals sending letters all over Europe – the dataset is taken from the blog http://www.martingrandjean.ch/gephi-introduction. You can find the actual data files at http://bit.ly/1pw1l2c (nodes) and http://bit.ly/1S1DH4I (edges).
File -> Import Spredsheet to load Nodes1.csv as “nodes table” (make sure Latitude/Longitude are loaded as Double) and Edges1.csv as “edges table”. Inspect the data in Data Laboratory -> Data Table.
In Overview -> Appearance panel set Nodes + Size + Attribute to Degree to 10-60 (size by Degree Centrality = number of connections) and Nodes + Color + Attribute to Degree as well in reverse.
In Overview -> Appearance panel set Edges + Color + Unique to grey.
Run Fruchterman-Reingold layout until convergence.
Run Force Atlas 2 layout until convergence. Try with/without Prevent Overlap.
Colour nodes by Eigenvector Centrality. Then by Modularity Class. Turn labels on.
Zoom in, inspect connections.
In Preview -> Preview Settings, click Show Labels, and then Refresh, and then Export as SVG. Open europe.svg in Chrome browser.
Load GeoLayout and NoOverlap plugins (Tools -> Plugins -> Available Plugins).
In Overview -> Layout panel select Geo Layout with Latitude=Latitude, Longitude=Longitude, Projection=Mercator and press Run
In Overview -> Layout panel select Nooverlap with ratio=0.1 and margin=0.3 to spread the nodes a little.
In Overview -> Graph panel on the left sidebar select Edit Node Attributes tool and click on any node to display its location
Can make nodes smaller, remove labels, make links yellow or orange, and in a separate image-editing program overlay the saved network onto a dark map http://www.martingrandjean.ch/wp-content/uploads/2015/10/Mapbase.svg for a cool effect.
There are good tutorials on the Gephi website:
You can find a copy of these slides at http://bit.ly/gephibits.