{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Multi-partite & shell node layouts\n\nDraw a multi-partite in successive layers or in concentric circles.\n\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "To draw a multi-partite graph in successive layers, use the :code:`multipartite` node layout.\nThe :code:`layers` argument indicates in which layer each node is plotted, as well as the order of layers.\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\npartitions = [\n    list(range(3)),\n    list(range(3, 9)),\n    list(range(9, 21))\n]\n\nedges = list(zip(np.repeat(partitions[0], 2), partitions[1])) \\\n      + list(zip(np.repeat(partitions[0], 2), partitions[1][1:])) \\\n      + list(zip(np.repeat(partitions[1], 2), partitions[2])) \\\n      + list(zip(np.repeat(partitions[1], 2), partitions[2][1:]))\n\nGraph(edges, node_layout='multipartite', node_layout_kwargs=dict(layers=partitions, reduce_edge_crossings=True), node_labels=True)\n\nplt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "To change the layout from the left-right orientation to a bottom-up orientation,\ncall the layout function directly and swap x and y coordinates of the node positions.\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, get_multipartite_layout\n\npartitions = [\n    list(range(3)),\n    list(range(3, 9)),\n    list(range(9, 21))\n]\n\nedges = list(zip(np.repeat(partitions[0], 2), partitions[1])) \\\n      + list(zip(np.repeat(partitions[0], 2), partitions[1][1:])) \\\n      + list(zip(np.repeat(partitions[1], 2), partitions[2])) \\\n      + list(zip(np.repeat(partitions[1], 2), partitions[2][1:]))\n\nnode_positions = get_multipartite_layout(edges, partitions, reduce_edge_crossings=True)\nnode_positions = {node : (x, y) for node, (y, x) in node_positions.items()}\n\nGraph(edges, node_layout=node_positions, node_labels=True)\n\nplt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "To draw a multi-partite graph in concentric circles, use the :code:`shell` node layout.\nThe :code:`shells` argument indicates in which circle each node is plotted, as well as the order of shells.\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\npartitions = [\n    list(range(3)),\n    list(range(3, 9)),\n    list(range(9, 21))\n]\n\nedges = list(zip(np.repeat(partitions[0], 2), partitions[1])) \\\n      + list(zip(np.repeat(partitions[0], 2), partitions[1][1:])) \\\n      + list(zip(np.repeat(partitions[1], 2), partitions[2])) \\\n      + list(zip(np.repeat(partitions[1], 2), partitions[2][1:]))\n\nGraph(edges, node_layout='shell', node_layout_kwargs=dict(shells=partitions, reduce_edge_crossings=True), node_labels=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
}