Desktop Browsers Market Share with Plotapi Pie Fight

Preamble

In [1]:
from plotapi import PieFight
import json

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

Introduction

In this notebook we're going to use Plotapi Pie Fight to visualise desktop browser market share over time. We"ll use Python, but Plotapi can be used from any programming language.

Dataset

We're going to use data that has been published by multiple sources for different periods, as there is no single data source that covers everything. These are:

  • 1994 - 1995: GVU WWW user survey
  • 1996 - 1998: EWS Web Server at UIUC
  • 1999 - 2001: WebSideStory
  • 2002 - 2008: OneStat.com
  • 2009-2021: StatCounter

The popup text that describes different events was taken from Wikipedia.

Browsers that did not have significant market share have been grouped and labelled as "Others".

In [2]:
with open("desktop_browsers.json", "r") as f:
    data = json.load(f)
    
samples = data['samples']
nodes = data['nodes']
events = data['events']

Visualisation

Let's use Plotapi Pie Fight for this visualisation, you can see more examples in the Gallery.

In [5]:
PieFight(samples, 
         nodes=nodes,
         events=events,
         rotate=30,
         interval=750,
         event_pause=False,
         event_duration=10000,
         format_current_order="0.2f", 
         value_suffix="%",
         autohide_labels=False).show()
Plotapi - Pie Fight Diagram

IMDb Top 1000 with Plotapi Chord

Preamble

In [1]:
from plotapi import Chord
import json

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

Introduction

In this notebook we're going to use Plotapi Chord to visualise the co-occurrences of genres in the IMDb "Top 1000" (Sorted by IMDb Rating Descending). We"ll use Python, but Plotapi can be used from any programming language.

In a chord diagram (or radial network), entities are arranged radially as segments with their relationships visualised by ribbons that connect them. The size of the segments illustrates the numerical proportions, whilst the size of the arc illustrates the significance of the relationships. Chord diagrams are useful when trying to convey relationships between different entities, and they can be beautiful and eye-catching.

Dataset

We're going to use the latest IMDB top 1000 data which is available on their website. Let"s get loading the data.

In [2]:
with open("imdb_top_1000.json", "r") as f:
    data = json.load(f)
    
names = ['Action', 'Adventure', 'Animation', 'Biography', 'Comedy',
         'Crime', 'Drama', 'Family', 'Fantasy', 'Film-Noir',
         'History', 'Horror', 'Music', 'Musical', 'Mystery',
         'Romance', 'Sci-Fi', 'Sport', 'Thriller', 'War', 'Western']

Visualisation

Let's use Plotapi Chord for this visualisation, you can see more examples in the Gallery.

We're going to adjust some layout and template parameters, and flip the intro animation on too. We'll also configure the data table to hide the indices, and we'll make sure to compress our data table so we have a smaller output size. Finally, we've also set data_table_unique_column="Name", because we have instances where a title has 3 or more genres, and we don't want them to appear multiple times in the same data table selection.

Because we're using a data-table, we can also click on any part of the diagram to "lock" the selection.

In [4]:
Chord(
    data["matrix"],
    names,
    colors="movies",
    noun="titles",
    data_table_column_width=100,
    data_table_unique_column="Name",
    data_table_show_indices=False,
    compress=True,
    data_table=data["data_table"],
    animated_intro=True
).show()
Plotapi - Chord Diagram

Getting started with Plotapi Bar Fight

Preamble

In [1]:
from plotapi import BarFight

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

Introduction

Our first Plotapi 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 bars over time.

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

    {"order": 1, "name": "Plotapi Sankey", "value": 18},
    {"order": 1, "name": "Plotapi Terminus", "value": 24},
    {"order": 1, "name": "Plotapi Chord", "value": 29},
    {"order": 1, "name": "Plotapi Bar Fight", "value": 14},
    {"order": 1, "name": "Plotapi Secret", "value": 17},

    {"order": 2, "name": "Plotapi Sankey", "value": 24},
    {"order": 2, "name": "Plotapi Terminus", "value": 40},
    {"order": 2, "name": "Plotapi Chord", "value": 52},
    {"order": 2, "name": "Plotapi Bar Fight", "value": 19},
    {"order": 2, "name": "Plotapi Secret", "value": 42},

    {"order": 3, "name": "Plotapi Sankey", "value": 32},
    {"order": 3, "name": "Plotapi Terminus", "value": 62},
    {"order": 3, "name": "Plotapi Chord", "value": 72},
    {"order": 3, "name": "Plotapi Bar Fight", "value": 25},
    {"order": 3, "name": "Plotapi Secret", "value": 64},

    {"order": 4, "name": "Plotapi Sankey", "value": 38},
    {"order": 4, "name": "Plotapi Terminus", "value": 75},
    {"order": 4, "name": "Plotapi Chord", "value": 99},
    {"order": 4, "name": "Plotapi Bar Fight", "value": 45},
    {"order": 4, "name": "Plotapi Secret", "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.

Visualisation

Creating our first Bar 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]:
BarFight(samples).show()
Plotapi - Bar Fight Diagram

Here we can see the default behaviour of Plotapi Bar 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.

Getting started with Plotapi Pie Fight

Preamble

In [1]:
from plotapi import PieFight

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

Introduction

Our first Plotapi 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},
]

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 pie chart segment.
  • value the value of the segment at the associated point in time.

Visualisation

Creating our first Pie 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]:
PieFight(samples).show()
Plotapi - Pie Fight Diagram

Here we can see the default behaviour of Plotapi Pie 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.

Pokemon Trends Max with Plotapi Bar Fight

Preamble

In [1]:
from plotapi import BarFight
import json

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

Introduction

In this notebook we're going to use Plotapi Bar Fight to visualise Pokémon search trends over time. We"ll use Python, but Plotapi can be used from any programming language.

The core games are released in generations, each with different Pokémon. We'll include remakes and one popular spin-off - Pokémon Go!

Dataset

We're going to use Pokémon (Gen 1-8) data (a fork of which is available in this repository), combined with data from Google Trends. Let's get loading the data.

The "Interest over time"[1] was retrieved for every Pokemon from Google Trends, for each month between 2004 and 2021. Pikachu was consistently the most popular, so Pikachu was always used as the reference point for every Pokemon. What we're seeing in the plot is the cumulative sum over time.

[1] Interest over time Numbers represent search interest relative to the highest point on the chart for the given region and time. A value of 100 is the peak popularity for the term. A value of 50 means that the term is half as popular. A score of 0 means there was not enough data for this term.

In [2]:
with open("pokemon_trends.json", "r") as f:
    data = json.load(f)
    
samples = data['samples']
nodes = data['nodes']
events = data['events']

icon_base_url = "https://datacrayon.com/images/data-is-beautiful/pokemon_thumbs/"

Visualisation

Let's use Plotapi Bar Fight for this visualisation, you can see more examples in the Gallery.

We're going to adjust some layout and template parameters. These include:

  • event_pause=False: The visualisation won't pause every time an event is displayed.
  • top_n=30: By default, we'll only show 30 bars. We can add/remove bars ourselves by hovering over the visualisation and clicking the + and - buttons.
  • icon_padding=-20: Why a negative number? For this visualisation, as they have transparent backgrounds, I thought it would look nicer to have the Pokemon popping out of their bars.
In [3]:
BarFight(samples, nodes=nodes, events=events, icon_base_url=icon_base_url, event_pause=False,
         width=1000, height=1000, icon_padding=-20, top_n=30, interval=750, 
         background_color="white", border="10px solid black").show()
Plotapi - Bar Fight Diagram