Displaying Event Information


In [ ]:
from plotapi import PieFight

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


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


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

In [ ]:
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.

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 [ ]:
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 Pie 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!


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 [8]:
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.