{
  "nbformat_minor": 0, 
  "nbformat": 4, 
  "cells": [
    {
      "execution_count": null, 
      "cell_type": "code", 
      "source": [
        "%matplotlib inline"
      ], 
      "outputs": [], 
      "metadata": {
        "collapsed": false
      }
    }, 
    {
      "source": [
        "\n# Degree Rank\n\n\nRandom graph from given degree sequence.\nDraw degree rank plot and graph with matplotlib.\n\n"
      ], 
      "cell_type": "markdown", 
      "metadata": {}
    }, 
    {
      "execution_count": null, 
      "cell_type": "code", 
      "source": [
        "# Author: Aric Hagberg <aric.hagberg@gmail.com>\nimport networkx as nx\nimport matplotlib.pyplot as plt\n\nG = nx.gnp_random_graph(100, 0.02)\n\ndegree_sequence = sorted([d for n, d in G.degree()], reverse=True)\n# print \"Degree sequence\", degree_sequence\ndmax = max(degree_sequence)\n\nplt.loglog(degree_sequence, 'b-', marker='o')\nplt.title(\"Degree rank plot\")\nplt.ylabel(\"degree\")\nplt.xlabel(\"rank\")\n\n# draw graph in inset\nplt.axes([0.45, 0.45, 0.45, 0.45])\nGcc = sorted(nx.connected_component_subgraphs(G), key=len, reverse=True)[0]\npos = nx.spring_layout(Gcc)\nplt.axis('off')\nnx.draw_networkx_nodes(Gcc, pos, node_size=20)\nnx.draw_networkx_edges(Gcc, pos, alpha=0.4)\n\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"
      }
    }
  }
}