DataFrame to Samples Dict

Preamble

In [1]:
import pandas as pd
from plotapi import LineFight

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

Introduction

Plotapi BarFight, PieFight, and LineFight, expect a list of dict items that define the value of nodes over time. The following is an example of this data structure.

In [2]:
samples = [
    {"order": 2000.01, "name": "Sankey", "value": 10},
    {"order": 2000.01, "name": "Terminus", "value": 10},
    {"order": 2000.01, "name": "Chord", "value": 40},
    {"order": 2000.01, "name": "Bar Fight", "value": 90},
    {"order": 2000.01, "name": "Pie Fight", "value": 70},

    {"order": 2000.02, "name": "Sankey", "value": 30},
    {"order": 2000.02, "name": "Terminus", "value": 20},
    {"order": 2000.02, "name": "Chord", "value": 40},
    {"order": 2000.02, "name": "Bar Fight", "value": 120},
    {"order": 2000.02, "name": "Pie Fight", "value": 55},

    {"order": 2000.03, "name": "Sankey", "value": 35},
    {"order": 2000.03, "name": "Terminus", "value": 45},
    {"order": 2000.03, "name": "Chord", "value": 60},
    {"order": 2000.03, "name": "Bar Fight", "value": 85},
    {"order": 2000.03, "name": "Pie Fight", "value": 100},

    {"order": 2000.04, "name": "Sankey", "value": 25},
    {"order": 2000.04, "name": "Terminus", "value": 60},
    {"order": 2000.04, "name": "Chord", "value": 90},
    {"order": 2000.04, "name": "Bar Fight", "value": 50},
    {"order": 2000.04, "name": "Pie Fight", "value": 105},

    {"order": 2000.05, "name": "Sankey", "value": 60},
    {"order": 2000.05, "name": "Terminus", "value": 80},
    {"order": 2000.05, "name": "Chord", "value": 120},
    {"order": 2000.05, "name": "Bar Fight", "value": 30},
    {"order": 2000.05, "name": "Pie Fight", "value": 95},
]

Dataset

Let's work backwards to the DataFrame, our starting point for this data wrangling exercise.

In [8]:
df = (
    pd.DataFrame(samples)
    .pivot(index="order", columns="name")["value"]
    .reset_index()
    .rename_axis(None, axis=1)
)

df
Out[8]:
order Bar Fight Chord Pie Fight Sankey Terminus
0 2000.01 90 40 70 10 10
1 2000.02 120 40 55 30 20
2 2000.03 85 60 100 35 45
3 2000.04 50 90 105 25 60
4 2000.05 30 120 95 60 80

Great! Now let's work back to the samples dict.

Wrangling

Our journey back to the samples list of dict items will be through pandas.melt.

In [4]:
df_melted = pd.melt(
    df,
    id_vars="order",
    value_vars=list(df.columns[1:]),
    var_name="name",
    value_name="value",
)

df_melted.head(10)
Out[4]:
order name value
0 2000.01 Bar Fight 90
1 2000.02 Bar Fight 120
2 2000.03 Bar Fight 85
3 2000.04 Bar Fight 50
4 2000.05 Bar Fight 30
5 2000.01 Chord 40
6 2000.02 Chord 40
7 2000.03 Chord 60
8 2000.04 Chord 90
9 2000.05 Chord 120

We're nearly there. This next step is optional - we're going to sort by order.

In [5]:
df_melted = df_melted.sort_values("order")
df_melted.head(10)
Out[5]:
order name value
0 2000.01 Bar Fight 90
20 2000.01 Terminus 10
5 2000.01 Chord 40
15 2000.01 Sankey 10
10 2000.01 Pie Fight 70
1 2000.02 Bar Fight 120
21 2000.02 Terminus 20
6 2000.02 Chord 40
16 2000.02 Sankey 30
11 2000.02 Pie Fight 55

Now for the final step - let's get our list of dict items.

In [6]:
samples = df_melted.to_dict(orient="records")
samples
Out[6]:
[{'order': 2000.01, 'name': 'Bar Fight', 'value': 90},
 {'order': 2000.01, 'name': 'Terminus', 'value': 10},
 {'order': 2000.01, 'name': 'Chord', 'value': 40},
 {'order': 2000.01, 'name': 'Sankey', 'value': 10},
 {'order': 2000.01, 'name': 'Pie Fight', 'value': 70},
 {'order': 2000.02, 'name': 'Bar Fight', 'value': 120},
 {'order': 2000.02, 'name': 'Terminus', 'value': 20},
 {'order': 2000.02, 'name': 'Chord', 'value': 40},
 {'order': 2000.02, 'name': 'Sankey', 'value': 30},
 {'order': 2000.02, 'name': 'Pie Fight', 'value': 55},
 {'order': 2000.03, 'name': 'Terminus', 'value': 45},
 {'order': 2000.03, 'name': 'Sankey', 'value': 35},
 {'order': 2000.03, 'name': 'Pie Fight', 'value': 100},
 {'order': 2000.03, 'name': 'Chord', 'value': 60},
 {'order': 2000.03, 'name': 'Bar Fight', 'value': 85},
 {'order': 2000.04, 'name': 'Pie Fight', 'value': 105},
 {'order': 2000.04, 'name': 'Chord', 'value': 90},
 {'order': 2000.04, 'name': 'Sankey', 'value': 25},
 {'order': 2000.04, 'name': 'Bar Fight', 'value': 50},
 {'order': 2000.04, 'name': 'Terminus', 'value': 60},
 {'order': 2000.05, 'name': 'Pie Fight', 'value': 95},
 {'order': 2000.05, 'name': 'Chord', 'value': 120},
 {'order': 2000.05, 'name': 'Sankey', 'value': 60},
 {'order': 2000.05, 'name': 'Bar Fight', 'value': 30},
 {'order': 2000.05, 'name': 'Terminus', 'value': 80}]

Perfect! We're all done.

Visualisation

No Plotapi exercise is complete without a visualisation.

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

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.

In [7]:
LineFight(samples, format_current_order="0.2f").show()
Plotapi - Line Fight Diagram

Here we can see the default behaviour of Plotapi LineFight.

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.

Using the Temporal Format for the Order

Preamble

In [1]:
from plotapi import LineFight

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

Introduction

Our first Plotapi Line Fight Diagram!

Plotapi Line Fight is a beautiful and feature rich take on the popular Line Chart Race. As we can see, we have set our license details in the preamble with LineFight.set_license().

Dataset

Plotapi Line Fight expects at minimum a list of dictionary items, these will define the value of our lines over time.

In [2]:
samples = [
    {"order": 2000.01, "name": "Sankey", "value": 10},
    {"order": 2000.01, "name": "Terminus", "value": 10},
    {"order": 2000.01, "name": "Chord", "value": 40},
    {"order": 2000.01, "name": "Bar Fight", "value": 90},
    {"order": 2000.01, "name": "Pie Fight", "value": 70},

    {"order": 2000.02, "name": "Sankey", "value": 30},
    {"order": 2000.02, "name": "Terminus", "value": 20},
    {"order": 2000.02, "name": "Chord", "value": 40},
    {"order": 2000.02, "name": "Bar Fight", "value": 120},
    {"order": 2000.02, "name": "Pie Fight", "value": 55},

    {"order": 2000.03, "name": "Sankey", "value": 35},
    {"order": 2000.03, "name": "Terminus", "value": 45},
    {"order": 2000.03, "name": "Chord", "value": 60},
    {"order": 2000.03, "name": "Bar Fight", "value": 85},
    {"order": 2000.03, "name": "Pie Fight", "value": 100},

    {"order": 2000.04, "name": "Sankey", "value": 25},
    {"order": 2000.04, "name": "Terminus", "value": 60},
    {"order": 2000.04, "name": "Chord", "value": 90},
    {"order": 2000.04, "name": "Bar Fight", "value": 50},
    {"order": 2000.04, "name": "Pie Fight", "value": 105},

    {"order": 2000.05, "name": "Sankey", "value": 60},
    {"order": 2000.05, "name": "Terminus", "value": 80},
    {"order": 2000.05, "name": "Chord", "value": 120},
    {"order": 2000.05, "name": "Bar Fight", "value": 30},
    {"order": 2000.05, "name": "Pie Fight", "value": 95},
]

We can see that each dictionary item has three properties:

  • order which determines with time period this item belongs to. This should can be formatted as a date, e.g. YYYY.MM.DD.
  • name the name of the item, and the text that appears on the lines.
  • value the value of the lines at the associated point in time.

Visualisation

Creating our first Line Fight Diagram is as easy as calling Plotapi with our one input.

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!

Be sure to interact with the visualisation to see what the default settings can do!

In [3]:
LineFight(samples, format_current_order="0.2f").show()
Plotapi - Line Fight Diagram

Here we can see the default behaviour of Plotapi Line Fight.

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.

Changing Font Sizes

Preamble

In [1]:
from plotapi import Sankey

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

Introduction

The Plotapi Sankey diagram font-sizes changed independently.

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

Dataset

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

In [2]:
links = [
    {"source":"Group A", "target":"Rank 1", "value": 1000},
    {"source":"Group B", "target":"Rank 1", "value": 300},
    {"source":"Group B", "target":"Rank 2", "value": 600},
    {"source":"Group B", "target":"Rank 3", "value": 400},
    {"source":"Rank 1", "target":"Club A", "value": 700},
    {"source":"Rank 1", "target":"Club B", "value": 400},
    {"source":"Rank 1", "target":"Club C", "value": 200},
    {"source":"Rank 2", "target":"Club B", "value": 200},
    {"source":"Rank 2", "target":"Club C", "value": 400},
    {"source":"Rank 3", "target":"Withdrawn", "value": 400},
    {"source":"Club A", "target":"The Most Amazing Prize", "value": 500},
]

We can add many sources and targets in any arrangement.

Visualisation

The font-sizes can be adjusted through a combination of the following:

  • title_font_size - to change the title font-size.
  • node_font_size - to change the node label font-size.
  • link_font_size - to change the link label font-size.

Let's demonstrate these in action.

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!

Be sure to interact with the visualisation to see what the settings can do!

In [18]:
Sankey(links, title="Font-size demonstration",
       node_font_size=10,
       link_font_size=30,
       title_font_size=30).show()
Plotapi - Sankey Diagram

Below are the default sizes for reference.

In [19]:
Sankey(links, title="Font-size demonstration").show()
Plotapi - Sankey Diagram

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.

Getting started with Plotapi Pareto Front

Preamble

In [ ]:
from plotapi import ParetoFront

ParetoFront.set_license("your username", "your license key")
Your Plotapi API key has been saved in your local environment. You will not need to set it again.

Introduction

Our first Plotapi Pareto Front Diagram!

Plotapi Pareto Front is a beautiful and feature rich take on non-dominated sorting over time. As we can see, we have set our license details in the preamble with ParetoFront.set_license().

Dataset

Plotapi Pareto Front expects at minimum a list of dictionary items, these will define bi-objective solutions over time.

In [ ]:
samples = [
    {'order': 20200101, 'objv_1': 40, 'objv_2': 12},   
    {'order': 20200101, 'objv_1': 40, 'objv_2': 12},   
    {'order': 20200101, 'objv_1': 40, 'objv_2': 12},   

    {'order': 20200104, 'objv_1': 40, 'objv_2': 12},   
    {'order': 20200104, 'objv_1': 40, 'objv_2': 12},   
    {'order': 20200104, 'objv_1': 40, 'objv_2': 14},   

    {'order': 20200109, 'objv_1': 40, 'objv_2': 12},   
    {'order': 20200109, 'objv_1': 45, 'objv_2': 12},   
    {'order': 20200109, 'objv_1': 45, 'objv_2': 10},   

    {'order': 20200112, 'objv_1': 50, 'objv_2': 12},   
    {'order': 20200112, 'objv_1': 50, 'objv_2': 11},   
    {'order': 20200112, 'objv_1': 50, 'objv_2': 10},   

    {'order': 20200115, 'objv_1': 50, 'objv_2': 12},   
    {'order': 20200115, 'objv_1': 50, 'objv_2': 12},   
    {'order': 20200115, 'objv_1': 50, 'objv_2': 12},   

    {'order': 20200115, 'objv_1': 50, 'objv_2': 12},   
    {'order': 20200115, 'objv_1': 50, 'objv_2': 12},   
    {'order': 20200115, 'objv_1': 50, 'objv_2': 12},   

    {'order': 20200120, 'objv_1': 60, 'objv_2': 8},   
    {'order': 20200120, 'objv_1': 60, 'objv_2': 8},   
    {'order': 20200120, 'objv_1': 60, 'objv_2': 8},   

    {'order': 20200123, 'objv_1': 60, 'objv_2': 8},   
    {'order': 20200123, 'objv_1': 60, 'objv_2': 8},   
    {'order': 20200123, 'objv_1': 60, 'objv_2': 8},   
    {'order': 20200123, 'objv_1': 80, 'objv_2': 3},  
    {'order': 20200123, 'objv_1': 30, 'objv_2': 20},  

    {'order': 20200125, 'objv_1': 30, 'objv_2': 20},  
    {'order': 20200125, 'objv_1': 10, 'objv_2': 20}, 

    {'order': 20200129, 'objv_1': 120, 'objv_2': 50},  
    {'order': 20200129, 'objv_1': 50, 'objv_2': 120},   
    {'order': 20200129, 'objv_1': 50, 'objv_2': 120},   
    {'order': 20200129, 'objv_1': 50, 'objv_2': 120},    

    {'order': 20200130, 'objv_1': 100, 'objv_2': 100},      
]

We can see that each dictionary item has three properties:

  • order which determines with time period this item belongs to. This should be numerical, but can be formatted e.g. as dates.
  • objv_1 the first objective value, e.g. "weight".
  • objv_2 the second objective value, e.g. "reps".

We can also populate the events structure to present event text at specific times.

In [ ]:
events = [
    {
        "order": 20200101,
        "event": "My first ever gym visit!"
    },
    {
        "order": 20200109,
        "event": "I went a little heavier today!"
    },
    {
        "order": 20200120,
        "event": "Three solid sets of 60 kg!"
    },
    {
        "order": 20200129,
        "event": "Broke some records today!"
    }
]

Visualisation

Creating our first Pareto Front Diagram is as easy as calling Plotapi with our one input.

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!

Be sure to interact with the visualisation to see what the default settings can do!

In [ ]:
ParetoFront(samples, events=events, title="Bench Press",
            objv_1_unit=" kg", objv_2_unit=" reps",
            x_label="Weight(kg)", y_label="Reps").show()
PlotAPI - ParetoFront Diagram

Here we can see the default behaviour of Plotapi Pareto Front.

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.

Displaying Event Information

Preamble

In [1]:
from plotapi import LineFight

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

Introduction

Let's take a look at how we can display event content during our visualisation at different times. This can be useful for displaying additional information or images that are relevant to specific events.

Plotapi Line Fight is a beautiful and feature rich take on the popular Line Chart Race. As we can see, we have set our license details in the preamble with LineFight.set_license().

Dataset

Plotapi Line Fight expects at minimum a list of dictionary items, these will define the value of our segments over time.

In [2]:
samples = [
    {"order": 0, "name": "Sankey", "value": 10},
    {"order": 0, "name": "Terminus", "value": 10},
    {"order": 0, "name": "Chord", "value": 40},
    {"order": 0, "name": "Bar Fight", "value": 90},
    {"order": 0, "name": "Pie Fight", "value": 70},

    {"order": 1, "name": "Sankey", "value": 30},
    {"order": 1, "name": "Terminus", "value": 20},
    {"order": 1, "name": "Chord", "value": 40},
    {"order": 1, "name": "Bar Fight", "value": 120},
    {"order": 1, "name": "Pie Fight", "value": 55},

    {"order": 2, "name": "Sankey", "value": 35},
    {"order": 2, "name": "Terminus", "value": 45},
    {"order": 2, "name": "Chord", "value": 60},
    {"order": 2, "name": "Bar Fight", "value": 85},
    {"order": 2, "name": "Pie Fight", "value": 100},

    {"order": 3, "name": "Sankey", "value": 25},
    {"order": 3, "name": "Terminus", "value": 60},
    {"order": 3, "name": "Chord", "value": 90},
    {"order": 3, "name": "Bar Fight", "value": 50},
    {"order": 3, "name": "Pie Fight", "value": 105},

    {"order": 4, "name": "Sankey", "value": 60},
    {"order": 4, "name": "Terminus", "value": 80},
    {"order": 4, "name": "Chord", "value": 120},
    {"order": 4, "name": "Bar Fight", "value": 30},
    {"order": 4, "name": "Pie Fight", "value": 95},
]

We can see that each dictionary item has three properties:

  • order which determines with time period this item belongs to. This should be numerical, but can be formatted e.g. as dates.
  • name the name of the item, and the text that appears on the line.
  • value the value of the line at the associated point in time.

Next, we'll start specifying event content to appear at certain points during our visualisation. Plotapi Line Fight expects a list of dictionary items to configure each event.

In [3]:
events = [
    {
        "order": 0,
        "event": '<p>Event information content can be <b>formatted with HTML</b>!</p><p>You can even include CSS - the <a href ="https://plotapi.com">power</a> of both are available.</p>'
    },
    {
        "order": 1,
        "event": '<b>Something Special</b><br><img src="https://datacrayon.com/datasets/pokemon_img/150.png"><p>Something special happened here, probably!</p>'
    },
    {
        "order": 4,
        "event": '<p>By specifying a <b>duration</b>, an event can be displayed for longer than the default value - much like this one!</p>',
        "duration": 10000
    }
]

We can see that each dictionary item has three properties:

  • order, which determines with time period this event belongs to. This should correspond to the orders specified in the samples.
  • event, the HTML content of the event information popup.
  • duration, the maximum display duration for the corresponding event content.

By default, a Plotapi Line Fight visualisation will pause for the duration of an event. However, it can be configured to either continue running or wait for the user to press a continue button. Check the next section in the Plotapi Gallery for an example!

Visualisation

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!

Be sure to interact with the visualisation to see what the default settings can do!

In [4]:
LineFight(samples, event_pause=False,
         events=events).show()
Plotapi - Line Fight Diagram

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.

Changing the Colours and Icons

Preamble

In [1]:
from plotapi import LineFight

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

Introduction

Let's take a look at how we can change the colours and icons for nodes in our Line Fight diagram.

Plotapi Line Fight is a beautiful and feature rich take on the popular Line Chart Race. As we can see, we have set our license details in the preamble with LineFight.set_license().

Dataset

Plotapi Line Fight expects at minimum a list of dictionary items, these will define the value of our segments over time.

In [2]:
samples = [
    {"order": 0, "name": "Sankey", "value": 10},
    {"order": 0, "name": "Terminus", "value": 10},
    {"order": 0, "name": "Chord", "value": 40},
    {"order": 0, "name": "Bar Fight", "value": 90},
    {"order": 0, "name": "Pie Fight", "value": 70},

    {"order": 1, "name": "Sankey", "value": 30},
    {"order": 1, "name": "Terminus", "value": 20},
    {"order": 1, "name": "Chord", "value": 40},
    {"order": 1, "name": "Bar Fight", "value": 120},
    {"order": 1, "name": "Pie Fight", "value": 55},

    {"order": 2, "name": "Sankey", "value": 35},
    {"order": 2, "name": "Terminus", "value": 45},
    {"order": 2, "name": "Chord", "value": 60},
    {"order": 2, "name": "Bar Fight", "value": 85},
    {"order": 2, "name": "Pie Fight", "value": 100},

    {"order": 3, "name": "Sankey", "value": 25},
    {"order": 3, "name": "Terminus", "value": 60},
    {"order": 3, "name": "Chord", "value": 90},
    {"order": 3, "name": "Bar Fight", "value": 50},
    {"order": 3, "name": "Pie Fight", "value": 105},

    {"order": 4, "name": "Sankey", "value": 60},
    {"order": 4, "name": "Terminus", "value": 80},
    {"order": 4, "name": "Chord", "value": 120},
    {"order": 4, "name": "Bar Fight", "value": 30},
    {"order": 4, "name": "Pie Fight", "value": 95},
]

We can see that each dictionary item has three properties:

  • order which determines with time period this item belongs to. This should be numerical, but can be formatted e.g. as dates.
  • name the name of the item, and the text that appears on the element.
  • value the value of the element at the associated point in time.

Next, we'll start customising the elements, or nodes, that will represent our data over time. Plotapi Line Fight expects a list of dictionary items to configure each node.

In [3]:
nodes = [
    {
        "name": "Sankey",
        "color": "#ffd166", 
        "icon": "https://datacrayon.com/datasets/pokemon_img/003.png"
    },
    {
        "name": "Terminus",
        "color": "#06d6a0", 
        "icon": "https://datacrayon.com/datasets/pokemon_img/004.png"
    },
    {
        "name": "Chord",
        "color": "#118ab2", 
        "icon": "https://datacrayon.com/datasets/pokemon_img/025.png"
    },
    {
        "name": "Bar Fight",
        "color": "#073b4c", 
        "icon": "https://datacrayon.com/datasets/pokemon_img/151.png"
    },
    {
        "name": "Pie Fight",
        "color": "#ef476f", 
        "icon": "https://datacrayon.com/datasets/pokemon_img/232.png"
    }
]

We can see that each dictionary item has three properties:

  • name, the name of the item, which corresponds to names specified in the samples definitions above.
  • color, the desired colour of the elements (CSS colour e.g. "#073b4c" or "red").
  • icon, the location of the image to use for the icon.

Visualisation

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!

Be sure to interact with the visualisation to see what the default settings can do!

In [4]:
LineFight(samples,
         nodes=nodes).show()
Plotapi - Line Fight Diagram

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.

Getting started with Plotapi Line Fight

Preamble

In [1]:
from plotapi import LineFight

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

Introduction

Our first Plotapi Line Fight Diagram!

Plotapi Line Fight is a beautiful and feature rich take on the popular Line Chart Race. As we can see, we have set our license details in the preamble with LineFight.set_license().

Dataset

Plotapi Line Fight expects at minimum a list of dictionary items, these will define the value of our lines over time.

In [2]:
samples = [
    {"order": 0, "name": "Sankey", "value": 10},
    {"order": 0, "name": "Terminus", "value": 10},
    {"order": 0, "name": "Chord", "value": 40},
    {"order": 0, "name": "Bar Fight", "value": 90},
    {"order": 0, "name": "Pie Fight", "value": 70},

    {"order": 1, "name": "Sankey", "value": 30},
    {"order": 1, "name": "Terminus", "value": 20},
    {"order": 1, "name": "Chord", "value": 40},
    {"order": 1, "name": "Bar Fight", "value": 120},
    {"order": 1, "name": "Pie Fight", "value": 55},

    {"order": 2, "name": "Sankey", "value": 35},
    {"order": 2, "name": "Terminus", "value": 45},
    {"order": 2, "name": "Chord", "value": 60},
    {"order": 2, "name": "Bar Fight", "value": 85},
    {"order": 2, "name": "Pie Fight", "value": 100},

    {"order": 3, "name": "Sankey", "value": 25},
    {"order": 3, "name": "Terminus", "value": 60},
    {"order": 3, "name": "Chord", "value": 90},
    {"order": 3, "name": "Bar Fight", "value": 50},
    {"order": 3, "name": "Pie Fight", "value": 105},

    {"order": 4, "name": "Sankey", "value": 60},
    {"order": 4, "name": "Terminus", "value": 80},
    {"order": 4, "name": "Chord", "value": 120},
    {"order": 4, "name": "Bar Fight", "value": 30},
    {"order": 4, "name": "Pie Fight", "value": 95},
]

We can see that each dictionary item has three properties:

  • order which determines with time period this item belongs to. This should be numerical, but can be formatted e.g. as dates.
  • name the name of the item, and the text that appears on the lines.
  • value the value of the lines at the associated point in time.

Visualisation

Creating our first Line Fight Diagram is as easy as calling Plotapi with our one input.

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!

Be sure to interact with the visualisation to see what the default settings can do!

In [3]:
LineFight(samples).show()
Plotapi - Line Fight Diagram

Here we can see the default behaviour of Plotapi Line Fight.

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.

Event Information Modes

Preamble

In [1]:
from plotapi import BarFight

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

Introduction

Let's take a look at how we can change the colours and icons for nodes in our Bar Fight diagram.

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().

Dataset

Plotapi Bar Fight expects at minimum a list of dictionary items, these will define the value of our segments over time.

In [2]:
samples = [
    {"order": 0, "name": "Sankey", "value": 10},
    {"order": 0, "name": "Terminus", "value": 12},
    {"order": 0, "name": "Chord", "value": 8},
    {"order": 0, "name": "Bar Fight", "value": 9},
    {"order": 0, "name": "Pie Fight", "value": 12},

    {"order": 1, "name": "Sankey", "value": 18},
    {"order": 1, "name": "Terminus", "value": 24},
    {"order": 1, "name": "Chord", "value": 22},
    {"order": 1, "name": "Bar Fight", "value": 14},
    {"order": 1, "name": "Pie Fight", "value": 17},

    {"order": 2, "name": "Sankey", "value": 24},
    {"order": 2, "name": "Terminus", "value": 40},
    {"order": 2, "name": "Chord", "value": 32},
    {"order": 2, "name": "Bar Fight", "value": 19},
    {"order": 2, "name": "Pie Fight", "value": 42},

    {"order": 3, "name": "Sankey", "value": 32},
    {"order": 3, "name": "Terminus", "value": 62},
    {"order": 3, "name": "Chord", "value": 40},
    {"order": 3, "name": "Bar Fight", "value": 25},
    {"order": 3, "name": "Pie Fight", "value": 64},

    {"order": 4, "name": "Sankey", "value": 38},
    {"order": 4, "name": "Terminus", "value": 75},
    {"order": 4, "name": "Chord", "value": 55},
    {"order": 4, "name": "Bar Fight", "value": 45},
    {"order": 4, "name": "Pie Fight", "value": 120},
]

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.

In [3]:
events = [
    {
        "order": 0,
        "event": '<p>Event information content can be <b>formatted with HTML</b>!</p><p>You can even include CSS - the <a href ="https://plotapi.com">power</a> of both are available.</p>'
    },
    {
        "order": 1,
        "event": '<b>Something Special</b><br><img src="https://datacrayon.com/datasets/pokemon_img/150.png"><p>Something special happened here, probably!</p>'
    },
    {
        "order": 4,
        "event": '<p>By specifying a <b>duration</b>, an event can be displayed for longer than the default value - much like this one!</p>',
    }
]

Visualisation

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! Be sure to interact with the visualisation to see what the default settings can do!

Default Event Mode

Without any additional configuration, the default event mode will pause the visualisation for the event duration.

This duration is specified either per-event using the events structure above, or globally using the event_duration parameter as seen below.

In [4]:
BarFight(samples,
         events=events,
         event_duration=7500).show()
Plotapi - Bar Fight Diagram

Running Event Mode

By specifying event_pause=False, we can keep the visualisation running during the duration of the event content.

In this mode, the event duration is treated as a maximum duration, such that any subsequent events will interrupt the previous one.

In [5]:
BarFight(samples,
         events=events,
         event_pause=False).show()
Plotapi - Bar Fight Diagram

Interactive Event Mode

By specifying auto_proceed=False, we can pause the visualisation and require user interaction for it to continue, i.e. clicking the continue button.

In [6]:
BarFight(samples,
         events=events,
         auto_proceed=False).show()
Plotapi - Bar Fight Diagram

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.

Event Information Modes

Preamble

In [1]:
from plotapi import PieFight

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

Introduction

Let's take a look at changing how the event information is displayed during a Pie Fight diagram.

Plotapi Pie Fight is a beautiful and feature rich take on the popular Pie Chart Race. As we can see, we have set our license details in the preamble with PieFight.set_license().

Dataset

Plotapi Pie Fight expects at minimum a list of dictionary items, these will define the value of our segments over time.

In [2]:
samples = [
    {"order": 0, "name": "Sankey", "value": 10},
    {"order": 0, "name": "Terminus", "value": 12},
    {"order": 0, "name": "Chord", "value": 8},
    {"order": 0, "name": "Bar Fight", "value": 9},
    {"order": 0, "name": "Pie Fight", "value": 12},

    {"order": 1, "name": "Sankey", "value": 18},
    {"order": 1, "name": "Terminus", "value": 24},
    {"order": 1, "name": "Chord", "value": 22},
    {"order": 1, "name": "Bar Fight", "value": 14},
    {"order": 1, "name": "Pie Fight", "value": 17},

    {"order": 2, "name": "Sankey", "value": 24},
    {"order": 2, "name": "Terminus", "value": 40},
    {"order": 2, "name": "Chord", "value": 32},
    {"order": 2, "name": "Bar Fight", "value": 19},
    {"order": 2, "name": "Pie Fight", "value": 42},

    {"order": 3, "name": "Sankey", "value": 32},
    {"order": 3, "name": "Terminus", "value": 62},
    {"order": 3, "name": "Chord", "value": 40},
    {"order": 3, "name": "Bar Fight", "value": 25},
    {"order": 3, "name": "Pie Fight", "value": 64},

    {"order": 4, "name": "Sankey", "value": 38},
    {"order": 4, "name": "Terminus", "value": 75},
    {"order": 4, "name": "Chord", "value": 55},
    {"order": 4, "name": "Bar Fight", "value": 45},
    {"order": 4, "name": "Pie Fight", "value": 120},
]

Next, we'll start specifying event content to appear at certain points during our visualisation. Plotapi Pie Fight expects a list of dictionary items to configure each event.

In [3]:
events = [
    {
        "order": 0,
        "event": '<p>Event information content can be <b>formatted with HTML</b>!</p><p>You can even include CSS - the <a href ="https://plotapi.com">power</a> of both are available.</p>'
    },
    {
        "order": 1,
        "event": '<b>Something Special</b><br><img src="https://datacrayon.com/datasets/pokemon_img/150.png"><p>Something special happened here, probably!</p>'
    },
    {
        "order": 4,
        "event": '<p>By specifying a <b>duration</b>, an event can be displayed for longer than the default value - much like this one!</p>',
    }
]

Visualisation

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! Be sure to interact with the visualisation to see what the default settings can do!

Default Event Mode

Without any additional configuration, the default event mode will pause the visualisation for the event duration.

This duration is specified either per-event using the events structure above, or globally using the event_duration parameter as seen below.

In [4]:
PieFight(samples,
         events=events,
         event_duration=7500).show()
Plotapi - Pie Fight Diagram

Running Event Mode

By specifying event_pause=False, we can keep the visualisation running during the duration of the event content.

In this mode, the event duration is treated as a maximum duration, such that any subsequent events will interrupt the previous one.

In [5]:
PieFight(samples,
         events=events,
         event_pause=False).show()
Plotapi - Pie Fight Diagram

Interactive Event Mode

By specifying auto_proceed=False, we can pause the visualisation and require user interaction for it to continue, i.e. clicking the continue button.

In [6]:
PieFight(samples,
         events=events,
         auto_proceed=False).show()
Plotapi - Pie Fight Diagram

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.

Displaying Event Information

Preamble

In [1]:
from plotapi import BarFight

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

Introduction

Let's take a look at how we can display event content during our visualisation at different times. This can be useful for displaying additional information or images that are relevant to specific events.

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().

Dataset

Plotapi Bar Fight expects at minimum a list of dictionary items, these will define the value of our segments over time.

In [2]:
samples = [
    {"order": 0, "name": "Sankey", "value": 10},
    {"order": 0, "name": "Terminus", "value": 12},
    {"order": 0, "name": "Chord", "value": 8},
    {"order": 0, "name": "Bar Fight", "value": 9},
    {"order": 0, "name": "Pie Fight", "value": 12},

    {"order": 1, "name": "Sankey", "value": 18},
    {"order": 1, "name": "Terminus", "value": 24},
    {"order": 1, "name": "Chord", "value": 22},
    {"order": 1, "name": "Bar Fight", "value": 14},
    {"order": 1, "name": "Pie Fight", "value": 17},

    {"order": 2, "name": "Sankey", "value": 24},
    {"order": 2, "name": "Terminus", "value": 40},
    {"order": 2, "name": "Chord", "value": 32},
    {"order": 2, "name": "Bar Fight", "value": 19},
    {"order": 2, "name": "Pie Fight", "value": 42},

    {"order": 3, "name": "Sankey", "value": 32},
    {"order": 3, "name": "Terminus", "value": 62},
    {"order": 3, "name": "Chord", "value": 40},
    {"order": 3, "name": "Bar Fight", "value": 25},
    {"order": 3, "name": "Pie Fight", "value": 64},

    {"order": 4, "name": "Sankey", "value": 38},
    {"order": 4, "name": "Terminus", "value": 75},
    {"order": 4, "name": "Chord", "value": 55},
    {"order": 4, "name": "Bar Fight", "value": 45},
    {"order": 4, "name": "Pie Fight", "value": 120},
]

We can see that each dictionary item has three properties:

  • order which determines with time period this item belongs to. This should be numerical, but can be formatted e.g. as dates.
  • name the name of the item, and the text that appears on the bar.
  • value the value of the bar at the associated point in time.

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.

In [3]:
events = [
    {
        "order": 0,
        "event": '<p>Event information content can be <b>formatted with HTML</b>!</p><p>You can even include CSS - the <a href ="https://plotapi.com">power</a> of both are available.</p>'
    },
    {
        "order": 1,
        "event": '<b>Something Special</b><br><img src="https://datacrayon.com/datasets/pokemon_img/150.png"><p>Something special happened here, probably!</p>'
    },
    {
        "order": 4,
        "event": '<p>By specifying a <b>duration</b>, an event can be displayed for longer than the default value - much like this one!</p>',
        "duration": 10000
    }
]

We can see that each dictionary item has three properties:

  • order, which determines with time period this event belongs to. This should correspond to the orders specified in the samples.
  • event, the HTML content of the event information popup.
  • duration, the maximum display duration for the corresponding event content.

By default, a Plotapi Bar Fight visualisation will pause for the duration of an event. However, it can be configured to either continue running or wait for the user to press a continue button. Check the next section in the Plotapi Gallery for an example!

Visualisation

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!

Be sure to interact with the visualisation to see what the default settings can do!

In [4]:
BarFight(samples,
         events=events).show()
Plotapi - Bar Fight Diagram

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.