{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Preamble" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from plotapi import Sankey\n", "\n", "Sankey.set_license(\"your username\", \"your license key\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Introduction\n", "\n", "Plotapi Sankey makes use of popups (tooltips) to display more information when mousing over a node or link. \n", "\n", "Let's see how we can add to the popup text and adjust the layout and template variables.\n", "\n", "As we can see, we have set our license details in the preamble with `Sankey.set_license()`." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Dataset" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Plotapi Sankey expects a `list` of `dictionary` items, these will define the flow between a `source` and a `target`.\n", "\n", "We can add a `description` to each link to have it display within the popup. \n", "\n", "We can add `description`s to nodes by creating a node data structure that we will pass into Plotapi later." ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [], "source": [ "links = [\n", " {\"source\":\"Group A\", \"target\":\"Rank 1\", \"value\": 1000, \"description\": \"This was a great transition\"},\n", " {\"source\":\"Group B\", \"target\":\"Rank 1\", \"value\": 300, \"description\": \"This could have gone better\"},\n", " {\"source\":\"Group B\", \"target\":\"Rank 2\", \"value\": 600},\n", " {\"source\":\"Group B\", \"target\":\"Rank 3\", \"value\": 400},\n", " {\"source\":\"Rank 1\", \"target\":\"Club A\", \"value\": 700},\n", " {\"source\":\"Rank 1\", \"target\":\"Club B\", \"value\": 400},\n", " {\"source\":\"Rank 1\", \"target\":\"Club C\", \"value\": 200},\n", " {\"source\":\"Rank 2\", \"target\":\"Club B\", \"value\": 200},\n", " {\"source\":\"Rank 2\", \"target\":\"Club C\", \"value\": 400},\n", " {\"source\":\"Rank 3\", \"target\":\"Withdrawn\", \"value\": 400},\n", " {\"source\":\"Club A\", \"target\":\"The Most Amazing Prize\", \"value\": 500},\n", "]\n", "\n", "nodes = [\n", " {\"name\": \"Group A\", \"description\": 'Group A is funded by the organisers.
'},\n", " {\"name\": \"Group B\", \"description\": \"A long sentence to demonstrate popup width, a longish but not that long sentence indeed!\"}\n", "\n", "]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can add many `source`'s and `target`'s in any arrangement." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Visualisation" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We have included the `\"description\"` property in the links and nodes data structures above, meaning they will not appear within the corresponding popups. \n", "\n", "We can also set the following parameters:\n", "\n", "- `tooltips` - `true` to enable tooltips, `false` to disable them. Enabled by default.\n", "- `popup_width` - to change the popup width.\n", "- `noun` - to change the noun used in the popup text, defaults to \"instances\".\n", "- `link_verb` - to change the text used in the link popup text, defaults to \"occurs in \".\n", "- `node_verb` - to change the text used in the node popup text, defaults to \"occurs in \".\n", "- `link_conjunction` - to change the text used between the source and target name in a link popup. Defaults to a right-arrow, i.e \"\\u2192\". \n", "\n", "Let's demonstrate these below.\n", "\n", "Here we're using `.show()` which outputs to a Jupyter Notebook cell, however, we may want to output to an 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 settings can do!\n", "
" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "Plotapi - Sankey Diagram\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", "
\n", " \n", " \n", "\n", " \n", "\n", "\n", "\n", "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "Sankey(links, nodes=nodes,\n", " popup_width=400, noun=\"games\", link_verb=\"battled together in \", \n", " node_verb=\"battled in \", link_conjunction=\"Vs.\").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." ] } ], "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.9.1" } }, "nbformat": 4, "nbformat_minor": 4 }