Engaging plots, made easy.

Easily turn your data into engaging visualizations. Powerful API for coders. Powerful app for everyone.

main.py
notebook.ipynb
main.rs
from plotapi import Chord

Chord(matrix, names).show()

Visualizations Showcase

Preamble


Preamble

from pytrends.request import TrendReq

# Only need to run this once, the rest of requests will use the same session.
pytrend = TrendReq()

# Get Google Keyword Suggestions

search_term = 'Dragonite'
suggestions_dict = pytrend.suggestions(keyword=search_term)
#keyword = next((item for item in suggestions_dict if item["type"] == "Pokemon species"), search_term)
suggestions_dict
[{'mid': '/m/040nd1', 'title': 'Dragonite', 'type': 'Pokemon species'},
 {'mid': '/g/11h6dh8x3k', 'title': 'Dark Dragonite', 'type': 'Topic'},
 {'mid': '/m/04cv3_t', 'title': 'Dragonite International', 'type': 'Company'},
 {'mid': '/g/11g8_5lnr3', 'title': 'Enter the Dragonite', 'type': 'Topic'},
 {'mid': '/g/11by0z59vx',
  'title': 'Iris and the Rogue Dragonite!',
  'type': 'Topic'}]
/g/1215jfxl

pytrend.build_payload(kw_list=['/m/01nrwb'], timeframe='all')
pokemon_interest_over_time = pytrend.interest_over_time()
pokemon_interest_over_time.drop('isPartial', axis=1, inplace=True)
pokemon_interest_over_time


pytrend.build_payload(kw_list=['/m/01nrwb', '/g/121xk3zq'], timeframe='all')

# Interest Over Time
interest_over_time_df = pytrend.interest_over_time()
interest_over_time_df.drop('/m/01nrwb', axis=1, inplace=True)
interest_over_time_df.drop('isPartial', axis=1, inplace=True)
interest_over_time_df 

pokemon_interest_over_time = pd.concat([pokemon_interest_over_time, interest_over_time_df], axis=1)
pokemon_interest_over_time.loc['2019-12-01']
import pandas as pd

df = pd.read_csv("pokemon.csv")
df.head()
Unnamed: 0 pokedex_number name german_name japanese_name generation status species type_number type_1 ... against_ground against_flying against_psychic against_bug against_rock against_ghost against_dragon against_dark against_steel against_fairy
0 0 1 Bulbasaur Bisasam フシギダネ (Fushigidane) 1 Normal Seed Pokémon 2 Grass ... 1.0 2.0 2.0 1.0 1.0 1.0 1.0 1.0 1.0 0.5
1 1 2 Ivysaur Bisaknosp フシギソウ (Fushigisou) 1 Normal Seed Pokémon 2 Grass ... 1.0 2.0 2.0 1.0 1.0 1.0 1.0 1.0 1.0 0.5
2 2 3 Venusaur Bisaflor フシギバナ (Fushigibana) 1 Normal Seed Pokémon 2 Grass ... 1.0 2.0 2.0 1.0 1.0 1.0 1.0 1.0 1.0 0.5
3 3 3 Mega Venusaur Bisaflor フシギバナ (Fushigibana) 1 Normal Seed Pokémon 2 Grass ... 1.0 2.0 2.0 1.0 1.0 1.0 1.0 1.0 1.0 0.5
4 4 4 Charmander Glumanda ヒトカゲ (Hitokage) 1 Normal Lizard Pokémon 1 Fire ... 2.0 1.0 1.0 0.5 2.0 1.0 1.0 1.0 0.5 0.5

5 rows × 51 columns

for index, row in df.iterrows():
    dex = f"{row['pokedex_number']:03d}"
    url = f"https://datacrayon.com/dataset/pokemon_thumbs/{dex}.png"
    df.at[index,'URL'] = url
    
    
df = df.drop_duplicates(subset=['pokedex_number'])
df.at[40,'name']
for index, row in df.iterrows():
    search_term = row['name']
    suggestions_dict = pytrend.suggestions(keyword=search_term)
    keyword = next((item for item in suggestions_dict if item["type"].lower() == "Pokemon species".lower()), None)
    
    if(keyword == None):
        keyword = next((item for item in suggestions_dict if "Pokemon species".lower() in item["type"].lower()), None)


    
    print(f"{index} - {search_term} > {keyword}")
    
    df.at[index,'keyword'] = keyword['mid'] if keyword != None else search_term
    
    
df.to_csv("pokemon_trends_keywords_unmodified.csv")
df = pd.read_csv("pokemon_trends_keywords.csv")

pokemon_interest_over_time = pd.read_csv("pokemon_interest_over_time.csv", index_col='date')

pokemon_interest_over_time.index = pokemon_interest_over_time.index.astype(str)
pokemon_interest_over_time.index.dtype
dtype('O')
pokemon_interest_over_time.drop('/m/014wp5', axis=1, inplace=True)
pokemon_interest_over_time.drop('/m/014wp5.1', axis=1, inplace=True)
#pokemon_interest_over_time.drop('/m/040nd1', axis=1, inplace=True)
pokemon_interest_over_time.drop('/g/1215jfxl.1', axis=1, inplace=True)
pokemon_interest_over_time.drop('/g/1215jfxl', axis=1, inplace=True)
pokemon_interest_over_time.drop('/m/040nd1', axis=1, inplace=True)
#pytrend.build_payload(kw_list=['/m/01nrwb'], timeframe='all')
#pokemon_interest_over_time = pytrend.interest_over_time()
#pokemon_interest_over_time.drop('isPartial', axis=1, inplace=True)
#pokemon_interest_over_time

#pokemon_interest_over_time.drop('/m/0279f9', axis=1, inplace=True)




import time

for index, row in df.iterrows():
    search_term = row['keyword']
    if((search_term != "/m/01nrwb") and search_term not in pokemon_interest_over_time.columns):
        print(f"{index} - {row['name']}, {row['keyword']}")
        pytrend.build_payload(kw_list=['/m/01nrwb', search_term], timeframe='all')

        # Interest Over Time
        interest_over_time_df = pytrend.interest_over_time()
        interest_over_time_df.drop('/m/01nrwb', axis=1, inplace=True)
        interest_over_time_df.drop('isPartial', axis=1, inplace=True)
        interest_over_time_df 
        
        interest_over_time_df.index = interest_over_time_df.index.astype(str)
        pokemon_interest_over_time = pd.concat([pokemon_interest_over_time, interest_over_time_df], axis=1)
        pokemon_interest_over_time.to_csv("pokemon_interest_over_timeplus.csv")
        time.sleep(2.4)
    

    
28 - Nidoran♀, /m/02zymz
31 - Nidoran♂‚, /g/1215jfxl
148 - Dragonite, /m/040nd1
149 - Mewtwo, /m/014wp5
150 - Mew, /m/0279f9
pokemon_interest_over_time
/m/01nrwb /m/015smv /g/15dp8m9k /m/015sns /m/0g9r8 /m/01pzh3 /m/09l5c /m/015w32 /g/12b02s670 /m/015sp7 ... Regieleki Regidrago Glastrier Spectrier Calyrex /m/02zymz /g/1215jfxl /m/040nd1 /m/014wp5 /m/0279f9
date
2004-01-01 9.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0 0 0 2 5
2004-02-01 10.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0 0 0 1 6
2004-03-01 11.0 0.0 0.0 0.0 1.0 0.0 1.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0 0 0 1 5
2004-04-01 8.0 0.0 0.0 0.0 1.0 0.0 1.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0 0 0 1 6
2004-05-01 9.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0 0 0 1 5
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
2021-04-01 25.0 2.0 0.0 2.0 3.0 1.0 10.0 2.0 0.0 2.0 ... 0.0 0.0 0.0 0.0 0.0 0 0 2 5 4
2021-05-01 27.0 2.0 0.0 2.0 3.0 1.0 13.0 2.0 0.0 2.0 ... 0.0 0.0 0.0 0.0 0.0 0 0 4 5 4
2021-06-01 27.0 2.0 0.0 2.0 3.0 1.0 14.0 2.0 0.0 2.0 ... 0.0 0.0 0.0 0.0 0.0 0 0 2 5 4
2021-07-01 29.0 3.0 0.0 2.0 3.0 1.0 13.0 3.0 0.0 2.0 ... 0.0 0.0 0.0 0.0 1.0 0 0 3 9 4
2021-08-01 26.0 2.0 0.0 2.0 3.0 1.0 12.0 3.0 0.0 2.0 ... 0.0 0.0 0.0 0.0 1.0 0 0 2 5 5

212 rows × 895 columns

import pandas as pd
df = pd.read_csv("pokemon_trends_keywords.csv")
pokemon_interest_over_time = pd.read_csv("pokemon_interest_over_timeplus.csv", index_col="date")
pokemon_interest_over_time = pokemon_interest_over_time.cumsum()

names = ["Bug", "Dark", "Dragon", "Electric", "Fairy", "Fighting", "Fire", "Flying", "Ghost", "Grass", "Ground", "Ice", "Normal", "Poison", "Psychic", "Rock", "Steel", "Water"]
colors = ["#A6B91A", "#705746", "#6F35FC", "#F7D02C", "#D685AD", "#C22E28", "#EE8130", "#A98FF3", "#735797", "#7AC74C", "#E2BF65", "#96D9D6", "#A8A77A", "#A33EA1", "#F95587", "#B6A136", "#B7B7CE", "#6390F0"]
colors[names.index(type1)]
from colorthief import ColorThief
import urllib.request

urllib.request.urlretrieve('https://datacrayon.com/datasets/pokemon_thumbs/151.png', "pokeimg/151.png")

color_thief = ColorThief('./pokeimg/151.png')
dominant_color = color_thief.get_color(quality=1)
color = '#%02x%02x%02x' % dominant_color
from colorthief import ColorThief
from pathlib import Path


samples=[]
nodes=[]

for col in pokemon_interest_over_time.columns:
    #print(col)
    pokemon = df.loc[df['keyword'] == col]
    name = pokemon.name.values[0]

    dex = pokemon.pokedex_number.values[0]

    #print(name)
    type1 = pokemon.type_1.values[0]

    url = pokemon.URL.values[0]


    # COLOR THIEF
    my_file = Path(f"pokeimg/{dex}.png")

    if not my_file.is_file():
        urllib.request.urlretrieve(url, f"pokeimg/{dex}.png")

    color_thief = ColorThief(f'./pokeimg/{dex}.png')
    dominant_color = color_thief.get_color(quality=1)
    color = '#%02x%02x%02x' % dominant_color

    
    nodes.append({"name":name,
              #    "color": colors[names.index(type1)],
                  "color": color,
                 "icon": url})    
for index, row in pokemon_interest_over_time.iterrows():
    print(index)
    for col in pokemon_interest_over_time.columns:
        pokemon = df.loc[df['keyword'] == col]
        name = pokemon.name.values[0]
                          
        samples.append({"order": f'{index.replace("-", ".")[:-3].split(".")[0]}.{index.replace("-", ".")[:-3].split(".")[1]}',
                       "name": name,
                       "value":row[col]})
2004-01-01
2004-02-01
2004-03-01
2004-04-01
2004-05-01
2004-06-01
2004-07-01
2004-08-01
2004-09-01
2004-10-01
2004-11-01
2004-12-01
2005-01-01
2005-02-01
2005-03-01
2005-04-01
2005-05-01
2005-06-01
2005-07-01
2005-08-01
2005-09-01
2005-10-01
2005-11-01
2005-12-01
2006-01-01
2006-02-01
2006-03-01
2006-04-01
2006-05-01
2006-06-01
2006-07-01
2006-08-01
2006-09-01
2006-10-01
2006-11-01
2006-12-01
2007-01-01
2007-02-01
2007-03-01
2007-04-01
2007-05-01
2007-06-01
2007-07-01
2007-08-01
2007-09-01
2007-10-01
2007-11-01
2007-12-01
2008-01-01
2008-02-01
2008-03-01
2008-04-01
2008-05-01
2008-06-01
2008-07-01
2008-08-01
2008-09-01
2008-10-01
2008-11-01
2008-12-01
2009-01-01
2009-02-01
2009-03-01
2009-04-01
2009-05-01
2009-06-01
2009-07-01
2009-08-01
2009-09-01
2009-10-01
2009-11-01
2009-12-01
2010-01-01
2010-02-01
2010-03-01
2010-04-01
2010-05-01
2010-06-01
2010-07-01
2010-08-01
2010-09-01
2010-10-01
2010-11-01
2010-12-01
2011-01-01
2011-02-01
2011-03-01
2011-04-01
2011-05-01
2011-06-01
2011-07-01
2011-08-01
2011-09-01
2011-10-01
2011-11-01
2011-12-01
2012-01-01
2012-02-01
2012-03-01
2012-04-01
2012-05-01
2012-06-01
2012-07-01
2012-08-01
2012-09-01
2012-10-01
2012-11-01
2012-12-01
2013-01-01
2013-02-01
2013-03-01
2013-04-01
2013-05-01
2013-06-01
2013-07-01
2013-08-01
2013-09-01
2013-10-01
2013-11-01
2013-12-01
2014-01-01
2014-02-01
2014-03-01
2014-04-01
2014-05-01
2014-06-01
2014-07-01
2014-08-01
2014-09-01
2014-10-01
2014-11-01
2014-12-01
2015-01-01
2015-02-01
2015-03-01
2015-04-01
2015-05-01
2015-06-01
2015-07-01
2015-08-01
2015-09-01
2015-10-01
2015-11-01
2015-12-01
2016-01-01
2016-02-01
2016-03-01
2016-04-01
2016-05-01
2016-06-01
2016-07-01
2016-08-01
2016-09-01
2016-10-01
2016-11-01
2016-12-01
2017-01-01
2017-02-01
2017-03-01
2017-04-01
2017-05-01
2017-06-01
2017-07-01
2017-08-01
2017-09-01
2017-10-01
2017-11-01
2017-12-01
2018-01-01
2018-02-01
2018-03-01
2018-04-01
2018-05-01
2018-06-01
2018-07-01
2018-08-01
2018-09-01
2018-10-01
2018-11-01
2018-12-01
2019-01-01
2019-02-01
2019-03-01
2019-04-01
2019-05-01
2019-06-01
2019-07-01
2019-08-01
2019-09-01
2019-10-01
2019-11-01
2019-12-01
2020-01-01
2020-02-01
2020-03-01
2020-04-01
2020-05-01
2020-06-01
2020-07-01
2020-08-01
2020-09-01
2020-10-01
2020-11-01
2020-12-01
2021-01-01
2021-02-01
2021-03-01
2021-04-01
2021-05-01
2021-06-01
2021-07-01
2021-08-01
url
'https://datacrayon.com/images/data-is-beautiful/pokemon_thumbs/151.png'
sequence = list(dict.fromkeys([d['order'] for d in samples]))
sequence.sort()
sequence
['2004.01',
 '2004.02',
 '2004.03',
 '2004.04',
 '2004.05',
 '2004.06',
 '2004.07',
 '2004.08',
 '2004.09',
 '2004.10',
 '2004.11',
 '2004.12',
 '2005.01',
 '2005.02',
 '2005.03',
 '2005.04',
 '2005.05',
 '2005.06',
 '2005.07',
 '2005.08',
 '2005.09',
 '2005.10',
 '2005.11',
 '2005.12',
 '2006.01',
 '2006.02',
 '2006.03',
 '2006.04',
 '2006.05',
 '2006.06',
 '2006.07',
 '2006.08',
 '2006.09',
 '2006.10',
 '2006.11',
 '2006.12',
 '2007.01',
 '2007.02',
 '2007.03',
 '2007.04',
 '2007.05',
 '2007.06',
 '2007.07',
 '2007.08',
 '2007.09',
 '2007.10',
 '2007.11',
 '2007.12',
 '2008.01',
 '2008.02',
 '2008.03',
 '2008.04',
 '2008.05',
 '2008.06',
 '2008.07',
 '2008.08',
 '2008.09',
 '2008.10',
 '2008.11',
 '2008.12',
 '2009.01',
 '2009.02',
 '2009.03',
 '2009.04',
 '2009.05',
 '2009.06',
 '2009.07',
 '2009.08',
 '2009.09',
 '2009.10',
 '2009.11',
 '2009.12',
 '2010.01',
 '2010.02',
 '2010.03',
 '2010.04',
 '2010.05',
 '2010.06',
 '2010.07',
 '2010.08',
 '2010.09',
 '2010.10',
 '2010.11',
 '2010.12',
 '2011.01',
 '2011.02',
 '2011.03',
 '2011.04',
 '2011.05',
 '2011.06',
 '2011.07',
 '2011.08',
 '2011.09',
 '2011.10',
 '2011.11',
 '2011.12',
 '2012.01',
 '2012.02',
 '2012.03',
 '2012.04',
 '2012.05',
 '2012.06',
 '2012.07',
 '2012.08',
 '2012.09',
 '2012.10',
 '2012.11',
 '2012.12',
 '2013.01',
 '2013.02',
 '2013.03',
 '2013.04',
 '2013.05',
 '2013.06',
 '2013.07',
 '2013.08',
 '2013.09',
 '2013.10',
 '2013.11',
 '2013.12',
 '2014.01',
 '2014.02',
 '2014.03',
 '2014.04',
 '2014.05',
 '2014.06',
 '2014.07',
 '2014.08',
 '2014.09',
 '2014.10',
 '2014.11',
 '2014.12',
 '2015.01',
 '2015.02',
 '2015.03',
 '2015.04',
 '2015.05',
 '2015.06',
 '2015.07',
 '2015.08',
 '2015.09',
 '2015.10',
 '2015.11',
 '2015.12',
 '2016.01',
 '2016.02',
 '2016.03',
 '2016.04',
 '2016.05',
 '2016.06',
 '2016.07',
 '2016.08',
 '2016.09',
 '2016.10',
 '2016.11',
 '2016.12',
 '2017.01',
 '2017.02',
 '2017.03',
 '2017.04',
 '2017.05',
 '2017.06',
 '2017.07',
 '2017.08',
 '2017.09',
 '2017.10',
 '2017.11',
 '2017.12',
 '2018.01',
 '2018.02',
 '2018.03',
 '2018.04',
 '2018.05',
 '2018.06',
 '2018.07',
 '2018.08',
 '2018.09',
 '2018.10',
 '2018.11',
 '2018.12',
 '2019.01',
 '2019.02',
 '2019.03',
 '2019.04',
 '2019.05',
 '2019.06',
 '2019.07',
 '2019.08',
 '2019.09',
 '2019.10',
 '2019.11',
 '2019.12',
 '2020.01',
 '2020.02',
 '2020.03',
 '2020.04',
 '2020.05',
 '2020.06',
 '2020.07',
 '2020.08',
 '2020.09',
 '2020.10',
 '2020.11',
 '2020.12',
 '2021.01',
 '2021.02',
 '2021.03',
 '2021.04',
 '2021.05',
 '2021.06',
 '2021.07',
 '2021.08']
name
'Kubfu'
from plotapi import BarFight

BarFight.set_license("your username", "your license key")
BarFight(samples,
         interval=500, icon_padding=0,nodes=nodes, colors="rainbow", height=1000, top_n=20,
         background_color="white", border="10px solid #C9605A", skip_first=True).show()
PlotAPI - Bar Fight Diagram
Previous
Showcase