{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Arc Diagrams\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 ArcDiagram\n\n# Create a modular graph.\npartition_sizes = [5, 6, 7]\ng = nx.random_partition_graph(partition_sizes, 1, 0.1)\n\n# Create a dictionary that maps nodes to the community they belong to,\n# and set the node colors accordingly.\nnode_to_community = dict()\nnode = 0\nfor community_id, size in enumerate(partition_sizes):\n    for _ in range(size):\n        node_to_community[node] = community_id\n        node += 1\n\ncommunity_to_color = {\n    0 : 'tab:blue',\n    1 : 'tab:orange',\n    2 : 'tab:green',\n}\nnode_color = {node: community_to_color[community_id] for node, community_id in node_to_community.items()}\n\nArcDiagram(g, node_size=1, node_color=node_color, node_edge_width=0, edge_alpha=1., edge_width=0.1)\nplt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "By default, ArcDiagram optimises the node order such that the number of edge crossings is minimised.\nFor larger graphs, this process can take a long time.\nThe node order can be set explicitly using the :code:`node_order` argument.\nIn this case, no optimisation is attempted.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "ArcDiagram(g, node_order=range(len(g)), node_size=1, node_color=node_color, node_edge_width=0, edge_alpha=1., edge_width=0.1)"
      ]
    }
  ],
  "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
}