summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMridul Seth <seth.mridul@gmail.com>2021-05-14 20:27:10 +0200
committerGitHub <noreply@github.com>2021-05-14 11:27:10 -0700
commit5974a85f9054f00a32f4f9067ac618c71f126a83 (patch)
tree218fbe55ef27229bee6c80cfee080f266f1beaa5
parent56abf2edfb4c061e027dba1d98adaf3d98e38f4b (diff)
downloadnetworkx-5974a85f9054f00a32f4f9067ac618c71f126a83.tar.gz
make plots less dense, enable plotting for igraph (#4791)
Make igraph plotting example render in gallery
-rw-r--r--examples/external/plot_igraph.py29
-rw-r--r--requirements/example.txt2
2 files changed, 19 insertions, 12 deletions
diff --git a/examples/external/plot_igraph.py b/examples/external/plot_igraph.py
index 1e85c7b8..0099bbe3 100644
--- a/examples/external/plot_igraph.py
+++ b/examples/external/plot_igraph.py
@@ -15,30 +15,37 @@ import igraph as ig
# NetworkX to igraph
# ------------------
-G = nx.dense_gnm_random_graph(1000, 2000)
+G = nx.dense_gnm_random_graph(30, 40, seed=42)
# 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)
+h = ig.Graph.from_networkx(H)
+
+
+# Plot the same network with NetworkX and igraph
+fig, (ax0, ax1) = plt.subplots(nrows=1, ncols=2, figsize=(12, 6))
+
+# NetworkX draw
+ax0.set_title("Plot with NetworkX draw")
+nx.draw_kamada_kawai(H, node_size=50, ax=ax0)
-## TODO: uncomment this once python-igraph 0.9 is released
# igraph draw
-# layout = g.layout()
-# ig.plot(g, layout=layout)
+ax1.set_title("Plot with igraph plot")
+layout = h.layout_kamada_kawai()
+ig.plot(h, layout=layout, target=ax1)
+plt.axis("off")
+plt.show()
+
# %%
# igraph to NetworkX
# ------------------
-g = ig.Graph.GRG(100, 0.2)
+g = ig.Graph.GRG(30, 0.2)
G = g.to_networkx()
-nx.draw(G)
+nx.draw(G, node_size=50)
plt.show()
diff --git a/requirements/example.txt b/requirements/example.txt
index bea4d088..bc172488 100644
--- a/requirements/example.txt
+++ b/requirements/example.txt
@@ -3,4 +3,4 @@ momepy>=0.4
contextily>=1.0
seaborn>=0.11
cairocffi>=1.2
-python-igraph>=0.8.3
+python-igraph>=0.9