##// END OF EJS Templates
avoid copious warnings in interact tests...
avoid copious warnings in interact tests comm was mocked out, but in a way that makes traitlets complain

File last commit:

r16120:24b93a1d
r17926:3e28c1c9
Show More
Exploring Graphs.ipynb
116 lines | 58.0 KiB | text/plain | TextLexer

Explore Random Graphs Using NetworkX¶

In this example, we build a simple UI for exploring random graphs with NetworkX.

In [7]:
from IPython.html.widgets import interact
In [12]:
%matplotlib inline
import matplotlib.pyplot as plt
In [13]:
import networkx as nx
In [14]:
# wrap a few graph generation functions so they have the same signature

def random_lobster(n, m, k, p):
    return nx.random_lobster(n, p, p / m)

def powerlaw_cluster(n, m, k, p):
    return nx.powerlaw_cluster_graph(n, m, p)

def erdos_renyi(n, m, k, p):
    return nx.erdos_renyi_graph(n, p)

def newman_watts_strogatz(n, m, k, p):
    return nx.newman_watts_strogatz_graph(n, k, p)

def plot_random_graph(n, m, k, p, generator):
    g = generator(n, m, k, p)
    nx.draw(g)
    plt.show()
In [16]:
interact(plot_random_graph, n=(2,30), m=(1,10), k=(1,10), p=(0.0, 1.0, 0.001),
        generator={'lobster': random_lobster,
                   'power law': powerlaw_cluster,
                   'Newman-Watts-Strogatz': newman_watts_strogatz,
                   u'Erdős-Rényi': erdos_renyi,
                   });
No description has been provided for this image