{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Preamble" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "from plotapi import Terminus\n", "\n", "Terminus.set_license(\"your username\", \"your license key\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Introduction\n", "\n", "Let's look at one approach to handling data with very high values or many `source`s and `target`s. \n", "\n", "For example, if we had a dataset that included values that were in the millions, Terminus may end up trying to process and display a million or more pixels on-screen simultaneously. The result would likely be crashing the tab or browser! Whilst that can be managed with the previously discussed `pixel_batch_size` and `pixel_journey_duration`, that approach will likely result in an animation that lasts too long.\n", "\n", "Instead, we can start representing more than $1$ \"unit\" of our value per pixel. For example, we could use one pixel to represent $10$, $100$, or even $1000$ units of our value. \n", "\n", "Let's demonstrate this with a high-value dataset.\n", "\n", "As we can see, we have set our license details in the preamble with `Terminus.set_license()`." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Dataset" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Terminus expects a `list` of `dictionary` items, these will define the flow of pixels between a `source` and a `target`." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "links = [\n", " {\"source\":\"England\", \"target\":\"Germany\", \"value\": 100000},\n", " {\"source\":\"England\", \"target\":\"France\", \"value\": 300000},\n", " {\"source\":\"England\", \"target\":\"Spain\", \"value\": 500000},\n", " {\"source\":\"England\", \"target\":\"Italy\", \"value\": 400000},\n", " {\"source\":\"England\", \"target\":\"Japan\", \"value\": 8000},\n", "\n", " \n", " {\"source\":\"Ireland\", \"target\":\"Germany\", \"value\": 350000},\n", " {\"source\":\"Ireland\", \"target\":\"France\", \"value\": 375000},\n", " {\"source\":\"Ireland\", \"target\":\"Spain\", \"value\": 175000},\n", " {\"source\":\"Ireland\", \"target\":\"Italy\", \"value\": 5000},\n", " {\"source\":\"Ireland\", \"target\":\"Japan\", \"value\": 40000},\n", "]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can add many `source`'s and `target`'s! As they increase, we may need to adjust Terminus layout properties to accomodate the diagram's size and throughput." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Visualisation" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can see that we're working with a dataset that contains higher values than usual. Let's address this by setting `pixels_per_unit=100`, which means we'll be representing $100$ units with a single pixel, rather than $100$ units with $100$ pixels. We'll also need to increase the `stats_text_width` to make enough space for the bigger numbers.\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!
" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", " \n", " \n", " Plotapi - Terminus Diagram\n", " \n", " \n", " \n", "\n", " \n", "
\n", " \n", " \n", "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "Terminus(links, stats_text_width=100, colors=\"warm\",\n", " pixels_per_unit=100).show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can do so much more than what's presented in this example, and this is covered in other sections. If you want to see the full list of growing features, check out the Plotapi API 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 }