{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Highlight paths\n\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import matplotlib.pyplot as plt\nimport networkx as nx\n\nfrom netgraph import Graph\n\n# create a random geometric graph and plot it\ng = nx.random_geometric_graph(100, 0.15, seed=42)\nnode_positions = nx.get_node_attributes(g, 'pos')\nplot_instance = Graph(g,\n                      node_layout=node_positions,\n                      node_size=1,\n                      node_edge_width=0.1,\n                      edge_width=0.1)\n\n# select a random path in the network and plot it\npath = nx.shortest_path(g, 33, 66)\n\nfor node in path:\n    plot_instance.node_artists[node].radius = 1.5 * 1e-2\n    plot_instance.node_artists[node].set_color('orange')\n\nfor ii, node_1 in enumerate(path[:-1]):\n    node_2 = path[ii+1]\n    if (node_1, node_2) in plot_instance.edges:\n        edge = (node_1, node_2)\n    else: # the edge is specified in reverse node order\n        edge = (node_2, node_1)\n    plot_instance.edge_artists[edge].update_width(0.5 * 1e-2)\n    plot_instance.edge_artists[edge].set_color('red')\n    plot_instance.edge_artists[edge].set_alpha(1.0)\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
}