{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Preamble" ] }, { "cell_type": "code", "execution_count": null, "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 asymmetric (`symmetric=False`) Plotapi Chord diagram allows us to represent the value at each end of the relationship with a single ribbon. However, it may be more suitable to use two different ribbons with arrows to indicate the direction of the relationship. This is possible with Plotapi Chord.\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": null, "metadata": {}, "outputs": [], "source": [ "matrix = [\n", " [0, 5, 6, 4],\n", " [2, 0, 5, 4],\n", " [6, 5, 0, 4],\n", " [2, 4, 3, 0],\n", "]\n", "\n", "names = [\"Action\", \"Adventure\", \"Comedy\", \"Drama\"]" ] }, { "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", "
ActionAdventureComedyDrama
Action0564
Adventure2054
Comedy6504
Drama2430
\n", "
" ], "text/plain": [ " Action Adventure Comedy Drama\n", "Action 0 5 6 4\n", "Adventure 2 0 5 4\n", "Comedy 6 5 0 4\n", "Drama 2 4 3 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": [ "To enable directed mode, we only need to set the `directed` parameter to `true`.\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!" ] }, { "cell_type": "code", "execution_count": 7, "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", "\n", "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "Chord(matrix, names, directed=True, colors=\"yellow_blue\").show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The directed Chord diagram can be paired with `reverse_gradients=True` to make it easier to see where inbound/outbound relationships are coming from or going to.\n", "
" ] }, { "cell_type": "code", "execution_count": 6, "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", "\n", "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "Chord(matrix, names, directed=True, colors=\"yellow_blue\", reverse_gradients=True).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 }