draw_graph_union example of identical nodes and some overlapping edges

Author: Julia Len ([email protected])


Import packages

In [2]:
import matplotlib.pyplot as plt
import matplotlib as mpl
import networkx as nx
import visJS2jupyter.visualizations as visualizations
import imp
imp.reload(visualizations)
Out[2]:
<module 'visJS2jupyter.visualizations' from '/Users/Julia/anaconda/lib/python2.7/site-packages/visJS2jupyter/visualizations.pyc'>


Create two networks and graph their union

In [46]:
G1 = nx.connected_watts_strogatz_graph(50,5,.1)
G2 = nx.connected_watts_strogatz_graph(50,5,.1)

edges_1 = set(G1.edges())
edges_2 = set(G2.edges())
intersecting_edges = edges_1 & edges_2
edges_1_disjoint = edges_1 - intersecting_edges
edges_2_disjoint = edges_2 - intersecting_edges

for i in range(0,5):
    new_edge = intersecting_edges.pop()
    edges_1_disjoint.add(new_edge)
    edges_2_disjoint.add(new_edge)

G1.remove_edges_from(edges_1)
G1.add_edges_from(list(edges_1_disjoint))

G2.remove_edges_from(edges_2)
G2.add_edges_from(list(edges_2_disjoint))
In [54]:
visualizations.draw_graph_union(G1,G2,node_cmap=mpl.cm.cool,edge_cmap=mpl.cm.winter_r,edge_width=5,
                                edge_shadow_enabled=True,edge_shadow_size=2)
Out[54]:
Network | Basic usage