In [1]:
import pandas as pd
import networkx as nx
import matplotlib
import warnings
import matplotlib.pyplot as plt
warnings.filterwarnings('ignore')
%matplotlib inline
plt.rcParams["figure.figsize"] = (15,15)
G = nx.read_gml('./Mk_connections_graph')
G.remove_node('האירק')
In [2]:
#Reverting the Mks names since hebrew is printed reversed :)
def reverse(some_list):
return [item[::-1] for item in some_list]
def print_reversed(dictionary):
return [(key[::-1] , value) for (key, value) in sorted(dictionary.items() ,key=lambda x: x[1] ,reverse=True)]
In [3]:
heads_of_committees = set(['מיקי זוהר', 'משה גפני', 'איתן כבל'
,'אבי דיכטר', 'יואב קיש', 'דוד ביטן', 'צחי הנגבי',
'דוד אמסלם', 'ניסן סלומינסקי', 'אברהם נגוסה', 'יעקב מרגי',
'אלי אלאלוף' ,'שלי יחימוביץ' ,'עאידה תומא סלימאן',
'קארין אלהרר', 'אורי מקלב', 'יצחק וקנין', 'איל בן ראובן'])
def without_committee_heads(mks_list):
return [(mk,d) for (mk,d) in mks_list if mk not in heads_of_committees_reversed]
In [4]:
pos = nx.spring_layout(G, k=1, scale=10000)
In [5]:
def draw_graph(G, arrows=False):
nx.draw_networkx_nodes(G, pos)
nx.draw_networkx_labels(G, pos, font_size=16)
weights = set([])
for n1,n2 in G.edges():
weight = G.get_edge_data(n1,n2)['weight']
weights.add(weight)
for weight in weights:
edges_with_weight = [edge for edge in G.edges() if weight == G.get_edge_data(*edge)['weight']]
nx.draw_networkx_edges(G, pos, edgelist=edges_with_weight, width=weight, arrows=arrows, edge_color='b', arrow_style='->')
draw_graph(G)
In [6]:
def reverse(some_list):
return [item[::-1] for item in some_list]
def print_reversed(dictionary):
dictionary = dict(dictionary)
return [(key[::-1] , value) for (key, value) in sorted(dictionary.items() ,key=lambda x: x[1] ,reverse=True)]
In [15]:
print_reversed(G.degree())[:10]
Out[15]:
In [43]:
without_committee_heads(print_reversed(G.degree()))[:10]
Out[43]:
In [8]:
print_reversed(G.in_degree())[:10]
Out[8]:
Without head of the committees
In [44]:
without_committee_heads(print_reversed(G.in_degree()))[:10]
Out[44]:
In [20]:
print_reversed(G.out_degree())[:10]
Out[20]:
In [45]:
without_committee_heads(print_reversed(G.out_degree()))[:10]
Out[45]:
In [190]:
print_reversed(nx.degree_centrality(G))[:10]
Out[190]:
In [46]:
without_committee_heads(print_reversed(nx.degree_centrality(G)))[:10]
Out[46]:
In [6]:
def draw_out_subgraph_of_node(some_node, arrows=False):
some_node = some_node[::-1]
neighbors = list(G.neighbors(some_node))
neighbors.append(some_node)
draw_graph(G.subgraph(neighbors), arrows)
In [12]:
draw_out_subgraph_of_node('ראש הממשלה בנימין נתניהו')
draw_out_subgraph_of_node('בנימין נתניהו')
Benjamin Netanyahu doesn't attend the Knesset committees and even if he do he only talks to Yuli Edelstein.
In [31]:
def draw_in_subgraph_of_node(some_node, arrows=False):
some_node = some_node[::-1]
neighbors = list(G.to_undirected().neighbors(some_node))
neighbors.append(some_node)
draw_graph(G.subgraph(neighbors), arrows)
In [32]:
draw_in_subgraph_of_node('בנימין נתניהו')
A lot of people are talking about Benjamin Netanyahu. (Even though the committees should be subject-based)
Just to name a few: