{
  "nbformat_minor": 0, 
  "nbformat": 4, 
  "cells": [
    {
      "execution_count": null, 
      "cell_type": "code", 
      "source": [
        "%matplotlib inline"
      ], 
      "outputs": [], 
      "metadata": {
        "collapsed": false
      }
    }, 
    {
      "source": [
        "\n# Ego Graph\n\n\nExample using the NetworkX ego_graph() function to return the main egonet of\nthe largest hub in a Barab\u00e1si-Albert network.\n\n"
      ], 
      "cell_type": "markdown", 
      "metadata": {}
    }, 
    {
      "execution_count": null, 
      "cell_type": "code", 
      "source": [
        "# Author:  Drew Conway (drew.conway@nyu.edu)\n\nfrom operator import itemgetter\n\nimport matplotlib.pyplot as plt\nimport networkx as nx\n\nif __name__ == '__main__':\n    # Create a BA model graph\n    n = 1000\n    m = 2\n    G = nx.generators.barabasi_albert_graph(n, m)\n    # find node with largest degree\n    node_and_degree = G.degree()\n    (largest_hub, degree) = sorted(node_and_degree, key=itemgetter(1))[-1]\n    # Create ego graph of main hub\n    hub_ego = nx.ego_graph(G, largest_hub)\n    # Draw graph\n    pos = nx.spring_layout(hub_ego)\n    nx.draw(hub_ego, pos, node_color='b', node_size=50, with_labels=False)\n    # Draw ego as large and red\n    nx.draw_networkx_nodes(hub_ego, pos, nodelist=[largest_hub], node_size=300, node_color='r')\n    plt.show()"
      ], 
      "outputs": [], 
      "metadata": {
        "collapsed": false
      }
    }
  ], 
  "metadata": {
    "kernelspec": {
      "display_name": "Python 2", 
      "name": "python2", 
      "language": "python"
    }, 
    "language_info": {
      "mimetype": "text/x-python", 
      "nbconvert_exporter": "python", 
      "name": "python", 
      "file_extension": ".py", 
      "version": "2.7.12", 
      "pygments_lexer": "ipython2", 
      "codemirror_mode": {
        "version": 2, 
        "name": "ipython"
      }
    }
  }
}