Get the Books
Enjoying these notebooks and want to support the work? Check out the practical books on Data Science, Visualisation, and Evolutionary Algorithms.
Get the books
Using the Temporal Format for the Order
Support this work
You can support this work by getting the e-books. This notebook will always be available for free in its online format.
Preamble¶
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.
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!
LineFight(samples, format_current_order="0.2f").show()
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.
Support this work
You can support this work by getting the e-books. This notebook will always be available for free in its online format.
Plotapi, beautiful by default.
Let plotapi do the heavy lifting – enabling beautiful interactive visualisations with a single line of code (instead of hundreds).
Get Plotapi