{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Weighted Graphs (2)\n\nAlternative visualisation for a weighted graph using edge widths to represent the absolute edge weight,\nand colour to represent the sign of the weight.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import numpy as np\nimport matplotlib.pyplot as plt\n\nfrom netgraph import Graph\n\nweighted_cube = [\n    (0, 1, -0.1),\n    (1, 2, -0.2),\n    (2, 3, -0.4),\n    (3, 2,  0.0),\n    (3, 0, -0.2),\n    (4, 5,  0.7),\n    (5, 6,  0.9),\n    (6, 5, -0.2),\n    (6, 7,  0.5),\n    (7, 4,  0.1),\n    (0, 4,  0.5),\n    (1, 5, -0.3),\n    (5, 1, -0.4),\n    (2, 6,  0.8),\n    (3, 7,  0.4)\n]\n\nedge_width = {(u, v) : 3 * np.abs(w) for (u, v, w) in weighted_cube}\nedge_color = {(u, v) : 'blue' if w <=0 else 'red' for (u, v, w) in weighted_cube}\nGraph(weighted_cube, edge_width=edge_width, edge_color=edge_color, arrows=True)\n\nplt.show()"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.6.8"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}