Categories
Uncategorized

Draw Quick Graph with igraph – Python

You start with a pajek file, called something_pajek.net, then you run this code.

#!/usr/bin/python
# draw qick graph
# input: *_pajek.net
# output: *_graph.svg

# imports
from igraph import *
from os import listdir
from re import sub

# reads file name
def getThreadID():
	dirList=listdir(".")
	for dirFile in dirList:
		if dirFile.endswith("_pajek.net"):
			threadID=sub("_pajek.net","",dirFile)
			return threadID
threadID=str(getThreadID())

# read graph
g=read(threadID+"_pajek.net",format="pajek")

# graph settings
g.vs["color"]="white"
g.vs["label"]=""
g.es["color"]="gray"
graphStyle={}
graphStyle["layout"]=g.layout("fr")
graphStyle["vertex_size"]=2
graphStyle["margin"]=0

g.write_svg(threadID+"_graph.svg",**graphStyle)

You should end up with something like this.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s