{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Preamble" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from plotapi import BarFight\n", "import json\n", "\n", "BarFight.set_license(\"your username\", \"your license key\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Introduction\n", "\n", "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.\n", "\n", "The core games are released in generations, each with different Pokémon. We'll include remakes and one popular spin-off - Pokémon Go!" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Dataset" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We're going to use Pokémon (Gen 1-8) data (a fork of which is available in this [repository](https://github.com/shahinrostami/pokemon_dataset)), combined with data from [Google Trends](https://trends.google.com/trends/?geo=GB). Let's get loading the data.\n", "\n", "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.\n", "\n", "_[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._" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "with open(\"pokemon_trends.json\", \"r\") as f:\n", " data = json.load(f)\n", " \n", "samples = data['samples']\n", "nodes = data['nodes']\n", "events = data['events']\n", "\n", "icon_base_url = \"https://datacrayon.com/images/data-is-beautiful/pokemon_thumbs/\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Visualisation" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's use Plotapi Bar Fight for this visualisation, you can see more examples [in the Gallery](https://plotapi.com/gallery/).\n", "\n", "We're going to adjust some layout and template parameters. These include:\n", "\n", "- `event_pause=False`: The visualisation won't pause every time an event is displayed.\n", "- `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.\n", "- `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.\n", "\n", "
" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\n", " \n", " Plotapi - Bar Fight Diagram\n", "\n", " \n", "\n", " \n", "\n", "\n", "\n", "
\n", " \n", "\n", "\n", "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "BarFight(samples, nodes=nodes, events=events, icon_base_url=icon_base_url, event_pause=False,\n", " width=1000, height=1000, icon_padding=-20, top_n=30, interval=750, \n", " background_color=\"white\", border=\"10px solid black\").show()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.1" } }, "nbformat": 4, "nbformat_minor": 4 }