## Plotapi, beautiful by default.

Let plotapi do the heavy lifting – enabling beautiful interactive visualisations with a single line of code (instead of hundreds).

# Handling High Values with Pixels Per Percentage

Contents

You can create beautiful, interactive, and engaging visualisations like this one with Plotapi in any programming language.

## Preamble¶

In [1]:
from plotapi import Terminus

Terminus.set_license("your username", "your license key")

## Introduction¶

Let's look at another approach to handling data with very high values or many sources and targets, much like we did with pixels_per_unit in an earlier example.

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.

Instead, we can start representing our data as a percentage. For example, we could represent $1%$ with $10$, $100$, or $1000$ pixels.

Let's demonstrate this with a high-value dataset.

As we can see, we have set our license details in the preamble with Terminus.set_license().

## Dataset¶

Terminus expects a list of dictionary items, these will define the flow of pixels between a source and a target.

In [2]:
links = [
{"source":"England", "target":"Germany", "value": 100000},
{"source":"England", "target":"France", "value": 300000},
{"source":"England", "target":"Spain", "value": 500000},
{"source":"England", "target":"Italy", "value": 400000},
{"source":"England", "target":"Japan", "value": 8000},

{"source":"Ireland", "target":"Germany", "value": 350000},
{"source":"Ireland", "target":"France", "value": 375000},
{"source":"Ireland", "target":"Spain", "value": 175000},
{"source":"Ireland", "target":"Italy", "value": 5000},
{"source":"Ireland", "target":"Japan", "value": 40000},
]

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.

## Visualisation¶

We can see that we're working with a dataset that contains higher values than usual. Let's address this by setting percentage_by_source=True, which enables the percentage feature, and then pixels_per_percentage=100, which means we will be using $100$ pixels to represent a single percent of a value. This also means our stats panel will display a percentage rather than the raw value.

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!

In [18]:
Terminus(links, stats_text_width=100, colors="cool",
percentage_by_source=True, pixels_per_percentage=100).show()
Plotapi - Terminus Diagram

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.