summaryrefslogtreecommitdiff
path: root/examples/drawing/plot_ego_graph.py
diff options
context:
space:
mode:
authorJarrod Millman <jarrod.millman@gmail.com>2019-11-10 15:39:27 -0800
committerJarrod Millman <jarrod.millman@gmail.com>2019-11-11 13:39:06 -0800
commitb7b8b07667e4aa061ca016e64e868f8213ca6a59 (patch)
tree10be1296bc8af0f5f6fc7700a3809654cfb65ad7 /examples/drawing/plot_ego_graph.py
parentcd2bde7856dc8057c8269696110ffb75795edf13 (diff)
downloadnetworkx-b7b8b07667e4aa061ca016e64e868f8213ca6a59.tar.gz
Update examples
Diffstat (limited to 'examples/drawing/plot_ego_graph.py')
-rw-r--r--examples/drawing/plot_ego_graph.py39
1 files changed, 20 insertions, 19 deletions
diff --git a/examples/drawing/plot_ego_graph.py b/examples/drawing/plot_ego_graph.py
index 40991034..002b2fd5 100644
--- a/examples/drawing/plot_ego_graph.py
+++ b/examples/drawing/plot_ego_graph.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
"""
=========
Ego Graph
@@ -8,26 +6,29 @@ Ego Graph
Example using the NetworkX ego_graph() function to return the main egonet of
the largest hub in a Barabási-Albert network.
"""
-# Author: Drew Conway (drew.conway@nyu.edu)
from operator import itemgetter
import matplotlib.pyplot as plt
import networkx as nx
-if __name__ == '__main__':
- # Create a BA model graph
- n = 1000
- m = 2
- G = nx.generators.barabasi_albert_graph(n, m)
- # find node with largest degree
- node_and_degree = G.degree()
- (largest_hub, degree) = sorted(node_and_degree, key=itemgetter(1))[-1]
- # Create ego graph of main hub
- hub_ego = nx.ego_graph(G, largest_hub)
- # Draw graph
- pos = nx.spring_layout(hub_ego)
- nx.draw(hub_ego, pos, node_color='b', node_size=50, with_labels=False)
- # Draw ego as large and red
- nx.draw_networkx_nodes(hub_ego, pos, nodelist=[largest_hub], node_size=300, node_color='r')
- plt.show()
+# Create a BA model graph
+n = 1000
+m = 2
+G = nx.generators.barabasi_albert_graph(n, m)
+
+# find node with largest degree
+node_and_degree = G.degree()
+(largest_hub, degree) = sorted(node_and_degree, key=itemgetter(1))[-1]
+
+# Create ego graph of main hub
+hub_ego = nx.ego_graph(G, largest_hub)
+
+# Draw graph
+pos = nx.spring_layout(hub_ego)
+nx.draw(hub_ego, pos, node_color="b", node_size=50, with_labels=False)
+
+# Draw ego as large and red
+options = {"node_size": 300, "node_color": "r"}
+nx.draw_networkx_nodes(hub_ego, pos, nodelist=[largest_hub], **options)
+plt.show()