diff options
author | Jarrod Millman <jarrod.millman@gmail.com> | 2020-12-07 18:00:22 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-07 21:00:22 -0500 |
commit | b8ca636525e12f13a491c3d738c965fe1ce7851c (patch) | |
tree | 6bfd67cd5da8d96e8b35f02fdda2bbcf926e2c0e /examples | |
parent | 6108e42fa70fec2d1af0f177bf5518d6b60981d6 (diff) | |
download | networkx-b8ca636525e12f13a491c3d738c965fe1ce7851c.tar.gz |
Add igraph example (#4404)
* Add igraph example
* Update comment to mention upcoming igraph release
Diffstat (limited to 'examples')
-rw-r--r-- | examples/external/plot_igraph.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/examples/external/plot_igraph.py b/examples/external/plot_igraph.py new file mode 100644 index 00000000..1e85c7b8 --- /dev/null +++ b/examples/external/plot_igraph.py @@ -0,0 +1,44 @@ +""" +====== +igraph +====== + +igraph (https://igraph.org/) is a popular network analysis package that +provides (among many other things) functions to convert to/from NetworkX. +""" + +import matplotlib.pyplot as plt +import networkx as nx +import igraph as ig + +# %% +# NetworkX to igraph +# ------------------ + +G = nx.dense_gnm_random_graph(1000, 2000) + +# largest connected component +components = nx.connected_components(G) +largest_component = max(components, key=len) +H = G.subgraph(largest_component) + +# networkx draw +nx.draw(H) +plt.show() + +# convert to igraph +g = ig.Graph.from_networkx(G) + +## TODO: uncomment this once python-igraph 0.9 is released +# igraph draw +# layout = g.layout() +# ig.plot(g, layout=layout) + +# %% +# igraph to NetworkX +# ------------------ + +g = ig.Graph.GRG(100, 0.2) +G = g.to_networkx() +nx.draw(G) +plt.show() |