#!/usr/local/bin/python import csv import igraph import math from igraph import * from itertools import chain #("ftn-weighted-network.csv") reader = csv.DictReader(open("bigrams-ground-truth.csv"), dialect="excel")#("bigrams-ground-truth.csv") g = igraph.Graph.DictList(vertices=None, edges=reader, directed=True) g.simplify() #g.to_directed() #print g.vs["name"] pr = g.pagerank() layout = g.layout_random() visual_style = {} visual_style["vertex_size"] = [float(15 *pr[v.index]) for v in g.vs] visual_style["vertex_label"] = g.vs["name"] visual_style["edge_color"] = 'red' #darkolivegreen4 visual_style["vertex_label_color"] = 'darkslateblue' visual_style["vertex_label_size"] = 5 visual_style["vertex_label_dist"] = 1.5 visual_style["edge_length"] = 20 #visual_style["edge_width"] = .10# g.es["weight"] # [float(x) for x in g.es["weight"]] #visual_style["edge_width"] = 30#[.07+10 *float(x) for x in g.es["weight"]] visual_style["edge_arrow_size"] = .01 visual_style["layout"] = layout visual_style["bbox"] = (800, 800) visual_style["margin"] = 20 plot(g ,**visual_style) plot(g, "/Users/ahamed/Publications/CICLing-Egypt/ftn-weighted-network.pdf", **visual_style) #g.vs["label"] = g.vs["name"] #print g.vcount() #print g.ecount() #pr = g.pagerank() #for v in g.vs: # print "{0}, {1}, {2}".format(v["name"], v.degree(), (pr[v.index])) ''' rankLogs = [] for r in pr : print r rankLogs.append(math.log(r)) #print len(pr) #bins = range(1, 2) #plt.xticks(bins, ["2^%s" % i for i in bins]) #n, bins, patches = plt.hist(rankLogs, log=True) #plt.xlabel('PageRank Value') #plt.ylabel('Frequency') #plt.title('Histogram of Term PageRanks') #plt.text(60, .025, r'$\mu=100,\ \sigma=15$') #plt.yticks(np.arange(0, 250, 10)) #plt.xticks(np.arange(min(pr), max(pr)+1, .01)) #plt.axis([0, 2.5, 1, 1000]) #plt.grid(True) #plt.show() # print ("Node" + "," + "Degree" + "," + "Eccentricity" + "," + "Closeness" + "," + "Betweennness") # for v in g.vs: # print (str(v["name"]) + "," + str(v.degree()) + "," + str(v.pagerank()) +"," + str(v.closeness()) + "," + str(v.betweenness())) layout = g.layout_random() visual_style = {} visual_style["vertex_size"] = 1 #visual_style["vertex_color"] = [color_dict[gender] for gender in g.vs["gender"]] visual_style["vertex_label"] = g.vs["name"] visual_style["edge_width"] = [1] visual_style["layout"] = layout visual_style["bbox"] = (1200, 1200) visual_style["margin"] = 20 plot(g, **visual_style) g.vs ''' ''' #plot(g, layout = layout) '''