{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Visualise Changes in Connectivity\n\nHere, we demonstrate how to visualise changes in connectivity over time.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import numpy as np\nimport matplotlib.pyplot as plt\n\nfrom matplotlib.animation import FuncAnimation\nfrom netgraph import Graph\n\n# Simulate a dynamic network with\n# - 5 frames / network states,\n# - with 10 nodes at each time point,\n# - an expected edge density of 25% at each time point\ntotal_frames = 5\ntotal_nodes = 10\nadjacency_matrix = np.random.rand(total_frames, total_nodes, total_nodes) < 0.25\n\nfig, ax = plt.subplots()\ng = Graph(np.ones((total_nodes, total_nodes)), edge_width=1.5, arrows=True, ax=ax) # initialise with fully connected graph\n\ndef update(ii):\n    for (jj, kk), artist in g.edge_artists.items():\n        # turn visibility of edge artists on or off, depending on the adjacency\n        if adjacency_matrix[ii, jj, kk]:\n            artist.set_visible(True)\n        else:\n            artist.set_visible(False)\n    return g.edge_artists.values()\n\nanimation = FuncAnimation(fig, update, frames=total_frames, interval=200, blit=True)"
      ]
    }
  ],
  "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
}