Visualizations Showcase
Pokemon Trends with Bar Fight
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.
Preamble
from plotapi import BarFight
import json
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.
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/datasets/pokemon_img/"
Visualization
Let's use PlotAPI Bar Fight for this visualisation.
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=15
: By default, we'll only show 15 bars. We can add/remove bars ourselves by hovering over the visualisation and clicking the+
and-
buttons. -
rescale_top_couple=0.1
: Pikachu is too popular! This made all the other bars too small. With this setting, we can make sure the difference between the #1 and #2 bars is only ever 10% of the plot width. -
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.
plot = BarFight(
samples,
nodes=nodes,
events=events,
icon_base_url=icon_base_url,
event_pause=False,
height=800,
icon_padding=-20,
top_n=15,
rescale_top_couple=0.1,
interval=750,
background_color="white",
border="10px solid #420a91",
)
Display inline
plot
Upload to cloud
With our plot created, let's upload it to PlotAPI cloud and get a shareable link.
plot.upload(
name="Pokémon Trends",
description="""In this notebook we're going to use PlotAPI Bar Fight to visualise Pokémon search trends over time.""",
public=True,
)