Example #1
0
def multimode_graph():
    '''
    This function calls the plot_multimode function to display a multimode graph
    for more information on multimode graphs see the comments in the source code 
    of that library. 
    '''
    ## Clear plot area. This is needed every time a new plot comes
    ## Otherwise plots will be drawn on top of another
    a.cla()
    ## Unpack tuple from existing network
    g = dble[0]
    dictz = dble[1]
    ## Define layout
    pos = nx.spring_layout(g)
    ## Plot graph
    mm.plot_multimode(g, type_string='questions', sizing=dictz)
    dense = nx.density(g)
    text.delete(1.0, END)
    text.insert(INSERT, "Density is: ")
    text.insert(INSERT, dense)
    ## Send plot to canvas
    canvas.draw()
Example #2
0
import multimode as mm
import triadic

# open the file
in_file=csv.reader(open('9_11_edgelist.txt','rb'))

g=net.Graph()
for line in in_file:
    g.add_edge(line[0],line[1],weight=line[2],conf=line[3])
    

#first, let's make sure that all nodes in the graph have the 'flight' attribute
for n in g.nodes_iter(): g.node[n]['flight']='None'

attrb=csv.reader(open('9_11_attrib.txt','rb'))
for line in attrb:
    g.node[line[0]]['flight']=line[1]


# Connected_component_subgraphs() returns a list of components, sorted largest to smallest
components=net.connected_component_subgraphs(g)

# pick the first and largest component
cc = components[0]

# type-string tells the function what attribute to differentiate on
mm.plot_multimode(cc,type_string='flight')

# run triadic analysis
census, node_census = triadic.triadic_census(cc)
Example #3
0
## Obtain Affiliation network: this function returns a tuple
##containing a graph object and a dictionary that has all the questions
## per user and topic respectively

dble = afil.affiliation()

# Clear the canvas for plotting
a.cla()
#Unpack the tuple, g is the graph object and dictz is the dictionary
g = dble[0]
dictz = dble[1]
# Define the layout for the graph see networkx.draw documentation for more
pos = nx.spring_layout(g)
#Call plot function from library to plot Affiliate network
nx.write_graphml(g, "test.graphml")
mm.plot_multimode(g, type_string='questions', sizing=dictz)
census, node_census = triadic.triadic_census(g)

# Define drawing area for plot in GUI
canvas = FigureCanvasTkAgg(f, master=w)
canvas.show()
canvas.get_tk_widget().pack(side=TOP, fill=BOTH, expand=1)
###########################################################################
'''
This section of the code defines the actions that will be
performed by the buttons of the GUI. These actions have 
the functionality in the code but in this section they are not 
binded (related to) the buttons in the GUI
'''

Example #4
0

def trim_edges(g, weight=1):
    g2 = net.Graph()
    for f, to, edata in g.edges(data=True):
        if edata['weight'] > weight:
            g2.add_edge(f, to, edata)
            g2.node[f] = g.node[f]
            g2.node[to] = g.node[to]
    return g2


import multimode as mm

cancore = trim_edges(cannet, weight=50)
mm.plot_multimode(cancore, type_string='party')

pacnet = bi.weighted_projected_graph(g, pac_list, ratio=False)
paccore = trim_edges(pacnet, weight=50)


def sorted_map(dct):
    ds = sorted(dct.iteritems(), key=lambda (k, v): (-v, k))
    return ds


d = sorted_map(net.degree(paccore))
c = sorted_map(net.closeness_centrality(paccore))
inf_pacs = [pacs[pid] for pid, deg in d[:10]]
close_pacs = [pacs[pid] for pid, deg in c[:10]]
"""
Example #5
0
import networkx as net
import multimode as mm
import triadic

# open the file
in_file = csv.reader(open('9_11_edgelist.txt', 'r'))

g = net.Graph()
for line in in_file:
    g.add_edge(line[0], line[1], weight=line[2], conf=line[3])

# first, let's make sure that all nodes in the graph have the 'flight' attribute
for n in g.nodes():
    g.node[n]['flight'] = 'None'

attrb = csv.reader(open('9_11_attrib.txt', 'r'))
for line in attrb:
    g.node[line[0]]['flight'] = line[1]

# Connected_component_subgraphs() returns a list of components, sorted largest to smallest
components = list(net.connected_component_subgraphs(g))

# pick the first and largest component
cc = components[0]

# type-string tells the function what attribute to differentiate on
mm.plot_multimode(cc, type_string='flight')

# run triadic analysis
census, node_census = triadic.triadic_census(cc)
Example #6
0
cannet=bi.weighted_projected_graph(g, can_list, ratio=False)

def trim_edges(g, weight=1):
	g2=net.Graph()
	for f, to, edata in g.edges(data=True):
		if edata['weight'] > weight:
			g2.add_edge(f,to,edata)
			g2.node[f]=g.node[f]
			g2.node[to]=g.node[to]
	return g2

import multimode as mm

cancore=trim_edges(cannet, weight=50)
mm.plot_multimode(cancore, type_string='party')

pacnet=bi.weighted_projected_graph(g, pac_list, ratio=False)
paccore = trim_edges(pacnet, weight=50)


def sorted_map(dct):
    ds = sorted(dct.iteritems(), key=lambda (k,v): (-v,k))
    return ds

d=sorted_map(net.degree(paccore))
c=sorted_map(net.closeness_centrality(paccore))
inf_pacs=[pacs[pid] for pid,deg in d[:10]]
close_pacs=[pacs[pid] for pid,deg in c[:10]]