{
  "nbformat_minor": 0, 
  "nbformat": 4, 
  "cells": [
    {
      "execution_count": null, 
      "cell_type": "code", 
      "source": [
        "%matplotlib inline"
      ], 
      "outputs": [], 
      "metadata": {
        "collapsed": false
      }
    }, 
    {
      "source": [
        "\n# Napoleon Russian Campaign\n\n\nMinard's data from Napoleon's 1812-1813  Russian Campaign.\nhttp://www.math.yorku.ca/SCS/Gallery/minard/minard.txt\n\n\n"
      ], 
      "cell_type": "markdown", 
      "metadata": {}
    }, 
    {
      "execution_count": null, 
      "cell_type": "code", 
      "source": [
        "# Author: Aric Hagberg (hagberg@lanl.gov)\n\n#    Copyright (C) 2006-2017 by\n#    Aric Hagberg <hagberg@lanl.gov>\n#    Dan Schult <dschult@colgate.edu>\n#    Pieter Swart <swart@lanl.gov>\n#    All rights reserved.\n#    BSD license.\n\nimport matplotlib.pyplot as plt\nimport networkx as nx\n\n\ndef minard_graph():\n    data1 = \"\"\"\\\n24.0,54.9,340000,A,1\n24.5,55.0,340000,A,1\n25.5,54.5,340000,A,1\n26.0,54.7,320000,A,1\n27.0,54.8,300000,A,1\n28.0,54.9,280000,A,1\n28.5,55.0,240000,A,1\n29.0,55.1,210000,A,1\n30.0,55.2,180000,A,1\n30.3,55.3,175000,A,1\n32.0,54.8,145000,A,1\n33.2,54.9,140000,A,1\n34.4,55.5,127100,A,1\n35.5,55.4,100000,A,1\n36.0,55.5,100000,A,1\n37.6,55.8,100000,A,1\n37.7,55.7,100000,R,1\n37.5,55.7,98000,R,1\n37.0,55.0,97000,R,1\n36.8,55.0,96000,R,1\n35.4,55.3,87000,R,1\n34.3,55.2,55000,R,1\n33.3,54.8,37000,R,1\n32.0,54.6,24000,R,1\n30.4,54.4,20000,R,1\n29.2,54.3,20000,R,1\n28.5,54.2,20000,R,1\n28.3,54.3,20000,R,1\n27.5,54.5,20000,R,1\n26.8,54.3,12000,R,1\n26.4,54.4,14000,R,1\n25.0,54.4,8000,R,1\n24.4,54.4,4000,R,1\n24.2,54.4,4000,R,1\n24.1,54.4,4000,R,1\"\"\"\n    data2 = \"\"\"\\\n24.0,55.1,60000,A,2\n24.5,55.2,60000,A,2\n25.5,54.7,60000,A,2\n26.6,55.7,40000,A,2\n27.4,55.6,33000,A,2\n28.7,55.5,33000,R,2\n29.2,54.2,30000,R,2\n28.5,54.1,30000,R,2\n28.3,54.2,28000,R,2\"\"\"\n    data3 = \"\"\"\\\n24.0,55.2,22000,A,3\n24.5,55.3,22000,A,3\n24.6,55.8,6000,A,3\n24.6,55.8,6000,R,3\n24.2,54.4,6000,R,3\n24.1,54.4,6000,R,3\"\"\"\n    cities = \"\"\"\\\n24.0,55.0,Kowno\n25.3,54.7,Wilna\n26.4,54.4,Smorgoni\n26.8,54.3,Moiodexno\n27.7,55.2,Gloubokoe\n27.6,53.9,Minsk\n28.5,54.3,Studienska\n28.7,55.5,Polotzk\n29.2,54.4,Bobr\n30.2,55.3,Witebsk\n30.4,54.5,Orscha\n30.4,53.9,Mohilow\n32.0,54.8,Smolensk\n33.2,54.9,Dorogobouge\n34.3,55.2,Wixma\n34.4,55.5,Chjat\n36.0,55.5,Mojaisk\n37.6,55.8,Moscou\n36.6,55.3,Tarantino\n36.5,55.0,Malo-Jarosewii\"\"\"\n\n    c = {}\n    for line in cities.split('\\n'):\n        x, y, name = line.split(',')\n        c[name] = (float(x), float(y))\n\n    g = []\n\n    for data in [data1, data2, data3]:\n        G = nx.Graph()\n        i = 0\n        G.pos = {}  # location\n        G.pop = {}  # size\n        last = None\n        for line in data.split('\\n'):\n            x, y, p, r, n = line.split(',')\n            G.pos[i] = (float(x), float(y))\n            G.pop[i] = int(p)\n            if last is None:\n                last = i\n            else:\n                G.add_edge(i, last, **{r: int(n)})\n                last = i\n            i = i + 1\n        g.append(G)\n\n    return g, c\n\n\nif __name__ == \"__main__\":\n\n    (g, city) = minard_graph()\n\n    plt.figure(1, figsize=(11, 5))\n    plt.clf()\n    colors = ['b', 'g', 'r']\n    for G in g:\n        c = colors.pop(0)\n        node_size = [int(G.pop[n] / 300.0) for n in G]\n        nx.draw_networkx_edges(G, G.pos, edge_color=c, width=4, alpha=0.5)\n        nx.draw_networkx_nodes(G, G.pos, node_size=node_size, node_color=c, alpha=0.5)\n        nx.draw_networkx_nodes(G, G.pos, node_size=5, node_color='k')\n\n    for c in city:\n        x, y = city[c]\n        plt.text(x, y + 0.1, c)\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"
      }
    }
  }
}