{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Preamble" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from plotapi import BarFight\n", "\n", "BarFight.set_license(\"your username\", \"your license key\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Introduction\n", "\n", "Let's take a look at how we can change the colours and icons for nodes in our Bar Fight diagram.\n", "\n", "Plotapi Bar Fight is a beautiful and feature rich take on the popular Bar Chart Race. As we can see, we have set our license details in the preamble with `BarFight.set_license()`." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Dataset" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Plotapi Bar Fight expects at minimum a `list` of `dictionary` items, these will define the value of our segments over time." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "samples = [\n", " {\"order\": 0, \"name\": \"Sankey\", \"value\": 10},\n", " {\"order\": 0, \"name\": \"Terminus\", \"value\": 12},\n", " {\"order\": 0, \"name\": \"Chord\", \"value\": 8},\n", " {\"order\": 0, \"name\": \"Bar Fight\", \"value\": 9},\n", " {\"order\": 0, \"name\": \"Pie Fight\", \"value\": 12},\n", "\n", " {\"order\": 1, \"name\": \"Sankey\", \"value\": 18},\n", " {\"order\": 1, \"name\": \"Terminus\", \"value\": 24},\n", " {\"order\": 1, \"name\": \"Chord\", \"value\": 22},\n", " {\"order\": 1, \"name\": \"Bar Fight\", \"value\": 14},\n", " {\"order\": 1, \"name\": \"Pie Fight\", \"value\": 17},\n", "\n", " {\"order\": 2, \"name\": \"Sankey\", \"value\": 24},\n", " {\"order\": 2, \"name\": \"Terminus\", \"value\": 40},\n", " {\"order\": 2, \"name\": \"Chord\", \"value\": 32},\n", " {\"order\": 2, \"name\": \"Bar Fight\", \"value\": 19},\n", " {\"order\": 2, \"name\": \"Pie Fight\", \"value\": 42},\n", "\n", " {\"order\": 3, \"name\": \"Sankey\", \"value\": 32},\n", " {\"order\": 3, \"name\": \"Terminus\", \"value\": 62},\n", " {\"order\": 3, \"name\": \"Chord\", \"value\": 40},\n", " {\"order\": 3, \"name\": \"Bar Fight\", \"value\": 25},\n", " {\"order\": 3, \"name\": \"Pie Fight\", \"value\": 64},\n", "\n", " {\"order\": 4, \"name\": \"Sankey\", \"value\": 38},\n", " {\"order\": 4, \"name\": \"Terminus\", \"value\": 75},\n", " {\"order\": 4, \"name\": \"Chord\", \"value\": 55},\n", " {\"order\": 4, \"name\": \"Bar Fight\", \"value\": 45},\n", " {\"order\": 4, \"name\": \"Pie Fight\", \"value\": 120},\n", "]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Next, we'll start specifying event content to appear at certain points during our visualisation. Plotapi Bar Fight expects a `list` of `dictionary` items to configure each event." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "events = [\n", " {\n", " \"order\": 0,\n", " \"event\": '

Event information content can be formatted with HTML!

You can even include CSS - the power of both are available.

'\n", " },\n", " {\n", " \"order\": 1,\n", " \"event\": 'Something Special

Something special happened here, probably!

'\n", " },\n", " {\n", " \"order\": 4,\n", " \"event\": '

By specifying a duration, an event can be displayed for longer than the default value - much like this one!

',\n", " }\n", "]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Visualisation" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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", "Be sure to interact with the visualisation to see what the default settings can do!" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Default Event Mode\n", "\n", "Without any additional configuration, the default event mode will pause the visualisation for the event `duration`. \n", "\n", "This duration is specified either per-event using the `events` structure above, or globally using the `event_duration` parameter as seen below." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\n", " \n", " Plotapi - Bar Fight Diagram\n", "\n", " \n", "\n", " \n", "\n", "\n", "\n", "
\n", " \n", "\n", "\n", "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "BarFight(samples,\n", " events=events,\n", " event_duration=7500).show()" ] }, { "cell_type": "markdown", "metadata": { "tags": [] }, "source": [ "## Running Event Mode\n", "\n", "By specifying `event_pause=False`, we can keep the visualisation running during the duration of the event content.\n", "\n", "In this mode, the event `duration` is treated as a _maximum_ duration, such that any subsequent events will interrupt the previous one." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\n", " \n", " Plotapi - Bar Fight Diagram\n", "\n", " \n", "\n", " \n", "\n", "\n", "\n", "
\n", " \n", "\n", "\n", "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "BarFight(samples,\n", " events=events,\n", " event_pause=False).show()" ] }, { "cell_type": "markdown", "metadata": { "tags": [] }, "source": [ "## Interactive Event Mode\n", "\n", "By specifying `auto_proceed=False`, we can pause the visualisation and require user interaction for it to continue, i.e. clicking the continue button.
" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\n", " \n", " Plotapi - Bar Fight Diagram\n", "\n", " \n", "\n", " \n", "\n", "\n", "\n", "
\n", " \n", "\n", "\n", "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "BarFight(samples,\n", " events=events,\n", " auto_proceed=False).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 (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 }