{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Visualise Changes in Node Properties\n\nHere, we visualise changes in the nodes of a network.\nWe change both, the colour and the size of the nodes.\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 / different node states,\n# - with 10 nodes at each time point, and\n# - an expected edge density of 25%.\ntotal_frames = 5\ntotal_nodes = 10\nadjacency_matrix = np.random.rand(total_nodes, total_nodes) < 0.25\nnode_values = np.random.rand(total_frames, total_nodes)\n\ncmap = plt.cm.viridis\n\nfig, ax = plt.subplots()\ng = Graph(adjacency_matrix, edge_width=1.5, arrows=True, ax=ax)\nax.axis([0, 1, 0, 1])\n\ndef update(ii):\n    for node, artist in g.node_artists.items():\n        value = node_values[ii, node]\n        artist.set_facecolor(cmap(value))\n        artist.set_edgecolor(cmap(value))\n        # The default node size is 3., which is rescaled internally\n        # to 0.03 to yield layouts comparable to networkx and igraph.\n        # As the expectation of `value` is 0.5, we multiply `value` by 6 * 0.01,\n        # and thus match the default node size on average.\n        artist.radius = 6 * 0.01 * value\n    return g.node_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
}