{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Preamble" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from plotapi import Chord\n", "\n", "Chord.set_license(\"your username\", \"your license key\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Introduction\n", "\n", "The bipartite feature of Plotapi Chord makes the biggest difference to the presentation and interpretation of the diagram. It splits the diagram in two, meaning relationships now happen between two different categorical sets.\n", "\n", "As we can see, we have set our license details in the preamble with `Chord.set_license()`" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Dataset" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Chord expects a list of names (`list[str]`) and a co-occurence matrix (`list[list[float]]`) as input." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "matrix = [\n", " [0, 0, 0, 1, 4, 1],\n", " [0, 0, 0, 1, 3, 2],\n", " [0, 0, 0, 1, 2, 2],\n", " [1, 1, 1, 0, 0, 0],\n", " [4, 3, 2, 0, 0, 0],\n", " [1, 2, 2, 0, 0, 0],\n", "]\n", "\n", "names = [\"Right 1\", \"Right 2\", \"Right 3\", \"Left 3\", \"Left 2\", \"Left 1\"]\n", "colors = [\"#7400B8\", \"#5E60CE\", \"#5684D6\", \"#56CFE1\", \"#64DFDF\", \"#80FFDB\"]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "It may look more clear if we present this as a table with the columns and indices labelled. This is entirely optional." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Right 1Right 2Right 3Left 3Left 2Left 1
Right 1000141
Right 2000132
Right 3000122
Left 3111000
Left 2432000
Left 1122000
\n", "
" ], "text/plain": [ " Right 1 Right 2 Right 3 Left 3 Left 2 Left 1\n", "Right 1 0 0 0 1 4 1\n", "Right 2 0 0 0 1 3 2\n", "Right 3 0 0 0 1 2 2\n", "Left 3 1 1 1 0 0 0\n", "Left 2 4 3 2 0 0 0\n", "Left 1 1 2 2 0 0 0" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import pandas as pd\n", "pd.DataFrame(matrix, columns=names, index=names)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Visualisation" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The bipartite mode is activated by setting the `bipartite` parameter to `True`.\n", "\n", "- `bipartite` enables/disables the bipartite chord diagram mode.\n", "- `bipartite_idx` sets the dividing point of the matrix.\n", "- `bipartite_size` sets the size of the spacing that creates the divide.\n", "- `colors` must be explicitly listed in bipartite mode.\n", "\n", "We have 6 categories in our matrix, and we wish to divide them directly down the middle, so our `bipartite_idx` will be $3$.\n", "\n", "Here we're using `.show()` which outputs to a Jupyter Notebook cell, however, we may want to output to a HTML file with `.to_html()` instead. More on the different output methods later!\n", "\n", "Be sure to interact with the visualisation to see what the default settings can do!\n", "
" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\n", "\n", "\n", "Plotapi - Chord Diagram\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
\n", "\n", " \n", "\n", "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "Chord(matrix, names, colors=colors, bipartite=True, bipartite_idx=3).show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can do so much more than what's presented in this example, and we'll cover this in later sections. If you want to see the full list of growing features, check out the Plotapi Documentation. and the Plotapi Gallery." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.9.1" } }, "nbformat": 4, "nbformat_minor": 4 }