{
  "nbformat_minor": 0, 
  "nbformat": 4, 
  "cells": [
    {
      "execution_count": null, 
      "cell_type": "code", 
      "source": [
        "%matplotlib inline"
      ], 
      "outputs": [], 
      "metadata": {
        "collapsed": false
      }
    }, 
    {
      "source": [
        "\n# Random Geometric Graph\n\n\nExample\n\n"
      ], 
      "cell_type": "markdown", 
      "metadata": {}
    }, 
    {
      "execution_count": null, 
      "cell_type": "code", 
      "source": [
        "import matplotlib.pyplot as plt\nimport networkx as nx\n\nG = nx.random_geometric_graph(200, 0.125)\n# position is stored as node attribute data for random_geometric_graph\npos = nx.get_node_attributes(G, 'pos')\n\n# find node near center (0.5,0.5)\ndmin = 1\nncenter = 0\nfor n in pos:\n    x, y = pos[n]\n    d = (x - 0.5)**2 + (y - 0.5)**2\n    if d < dmin:\n        ncenter = n\n        dmin = d\n\n# color by path length from node near center\np = dict(nx.single_source_shortest_path_length(G, ncenter))\n\nplt.figure(figsize=(8, 8))\nnx.draw_networkx_edges(G, pos, nodelist=[ncenter], alpha=0.4)\nnx.draw_networkx_nodes(G, pos, nodelist=p.keys(),\n                       node_size=80,\n                       node_color=p.values(),\n                       cmap=plt.cm.Reds_r)\n\nplt.xlim(-0.05, 1.05)\nplt.ylim(-0.05, 1.05)\nplt.axis('off')\nplt.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"
      }
    }
  }
}