{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Hive plot panel\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import os\n\nimport matplotlib.pyplot as plt\n\nimport nngt\n\n\nplt.rcParams.update({\n    \"figure.facecolor\": (0, 0, 0, 0),\n    \"axes.titlecolor\": \"grey\", \"text.color\": \"grey\"\n})\n\n\ndirpath  = os.path.abspath(os.getcwd())\nrootpath = os.path.abspath(dirpath + \"/../../..\")\n\n\n# load graph\n\ng = nngt.load_from_file(rootpath + \"/testing/Networks/rat_brain.graphml\",\n                        attributes=[\"weight\"], cleanup=True,\n                        attributes_types={\"weight\": float})\n\n\n# prepare attributes\n\ncc = nngt.analysis.local_clustering(g, weights=\"weight\")\n\ng.new_node_attribute(\"cc\", \"double\", values=cc)\n\ng.new_node_attribute(\"strength\", \"double\",\n                     values=g.get_degrees(weights=\"weight\"))\n\nflux = g.get_degrees(\"out\") - g.get_degrees(\"in\")\n\ng.new_node_attribute(\"flux\", \"double\", values=flux)\n\n\n# figure parameters\n\ncc_bins = [0, 0.1, 0.25, 0.6]\n\ntodo = [\"strength\", \"cc\", \"flux\"]\nbins = [3, cc_bins, 3]\n\n\n# make plot\n\nfig, axes = plt.subplots(len(todo), len(todo), figsize=(10, 9))\n\nfor i in range(len(todo)):\n    radial = todo[i]\n\n    for j in range(len(todo)):\n        ax_name = todo[j]\n        ax_bins = bins[j]\n\n        ax = axes[i, j]\n\n        if i == 0:\n            ax.set_title(ax_name)\n\n        if j == 0:\n            ax.set_ylabel(radial)\n\n        size = todo[list(set([0, 1, 2]).difference([i, j]))[0]]\n\n        nngt.plot.hive_plot(\n            g, radial, axes=ax_name, edge_alpha=0.1, nsize=size, max_nsize=50,\n            axes_bins=ax_bins, axes_units=\"native\", axis=ax, show_names=False)\n\nfor i in range(len(todo)):\n    fig.text(0.03, 0.8 - i*0.33, todo[i], rotation=90, fontsize=\"large\")\n\nplt.tight_layout()\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.8.10"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}