{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Node and Edge Labels\n\n## Labels\n\nIf the variables :code:`node_labels` and :code:`edge_labels` are set to :code:`True`,\nthe nodes and edges are labelled with the corresponding node and edge IDs.\nAlternatively, :code:`node_labels` and :code:`edge_labels` can be\ndictionaries that map node and edge IDs to custom strings.\n\n## Styling\n\nThe contents of the variables :code:`node_label_fontdict` and :code:`edge_label_fontdict`\nare passed to :code:`matplotlib.text.Text` to stylise the node label and edge label text objects.\nConsult the :code:`matplotlib.text.Text` documentation for a full list of available options.\nBy default, the following values differ from the defaults for :code:`matplotlib.text.Text`:\n\n- size (adjusted to fit into node artists if no :code:`node_label_offset` is used)\n- horizontalalignment (default here: :code:`'center'`)\n- verticalalignment (default here: :code:`'center'`)\n- clip_on (default here: :code:`False`)\n- zorder (default here: :code:`inf`)\n\n## Positioning\n\nEdge labels are always centred on the corresponding edges.\nThe position of the edge label along the edge can be controlled using the\n:code:`edge_label_position` argument:\n\n- :code:`0.0` : edge labels are placed at the head of the edge\n- :code:`0.5` : edge labels are placed at the centre of the edge (default)\n- :code:`1.0` : edge labels are placed at the tail of the edge\n\nIf :code:`edge_label_rotate` is True (default), edge labels are rotated such\nthat they have the same orientation as their edge.\nIf False, edge labels are not rotated; the angle of the text is parallel to the axis.\n\nBy default, node labels are centred on the corresponding nodes.\nHowever, they can also be offset using the :code:`node_label_offset` parameter.\nIf :code:`node_label_offset` is a (float dx, float dy) tuple,\nnode labels are offset by the corresponding amounts.\nIf :code:`node_label_offset` is a float, netgraph attempts to place node labels\nwithin that distance from node centres while avoiding collisions with node and edges.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import numpy as np\nimport matplotlib.pyplot as plt\nimport networkx as nx\n\nfrom netgraph import Graph\n\nfig, (ax1, ax2) = plt.subplots(1, 2)\n\ntriangle = [(0, 1), (0, 2), (1, 1), (1, 2), (2, 0)]\n\nnode_positions = {\n    0 : np.array([0.2, 0.2]),\n    1 : np.array([0.5, 0.8]),\n    2 : np.array([0.8, 0.2]),\n}\n\ng = Graph(\n    triangle,\n    node_layout=node_positions, edge_layout='curved', edge_layout_kwargs=dict(k=0.025),\n    node_labels={0 : 'a', 1 : 'b', 2 : 'c'},\n    edge_labels=True, edge_label_fontdict=dict(fontweight='bold'),\n    ax=ax1,\n)\n\nh = Graph(nx.complete_graph(7), edge_width=0.5, node_labels=True,\n      node_label_fontdict=dict(size=14), node_label_offset=0.075, ax=ax2)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Node and edge label properties can also be changed individually after an\ninitial draw using the standard :code:`matplotlib.text.Text` methods:\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "# make changes\ng.edge_label_artists[(0, 1)].set_style('italic')\ng.node_label_artists[1].set_color('hotpink')\n\n# force redraw to display changes\nfig.canvas.draw()"
      ]
    }
  ],
  "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
}