<jupyter_start><jupyter_text>100Viz 12: Reppin' LATAMSource: genius.com, musica.com, letras.com Notes: Data processed / cleaned before-hand.<jupyter_code>import plotly
import plotly.graph_objs as go
from plotly.offline import iplot, init_notebook_mode
import ipywidgets as widgets
import pandas as pd
# example
theta = [0, 22.5, 45, 67.5, 90]
fig1 = go.FigureWidget(data = [
    go.Barpolar(theta = theta, r = [1, 3, 2, 4,]),
    go.Barpolar(theta = theta, r = [3, 2, 4, 1,]),
    go.Barpolar(theta = theta, r = [2, 4, 1, 3,])
])

fig1
df = pd.read_csv("../data/raw/pos_top7.csv")
df['pos'].unique()
def make_chart(dataframe, artist = 'Residente'):
    
    df = dataframe
    
    condition_pos = ((df['pos'] == 'sustantivo') |
        (df['pos'] == 'verbo') |
        (df['pos'] == 'nombre propio') |
        (df['pos'] == 'adjetivo') |
        (df['pos'] == 'pronombre')
        )


    df = df[condition_pos].copy()

    artist_data = df[df['artista'] == artist]

    pos_top = ['sustantivo', 'verbo', 'nombre propio', 'adjetivo', 'pronombre']
    colors = ["#074a7e",  "#dc0d12", "#e4a100", "#02a3cd", "#dc0d7a",]

    angle = 90/5
    theta = [angle*0.5, 
             angle*1.5, 
             angle*2.5, 
             angle*3.5, 
             angle*4.5]

    fig_artist = go.FigureWidget(data = [
        go.Barpolar(theta = [angle*4], r = artist_data[artist_data['pos'] == pos_top[4]]['cuenta'], name = pos_top[4], width = 18, marker = dict(color = colors[0]), ),
        go.Barpolar(theta = [angle*3], r = artist_data[artist_data['pos'] == pos_top[3]]['cuenta'], name = pos_top[3], width = 18, marker = dict(color = colors[1])),
        go.Barpolar(theta = [angle*2], r = artist_data[artist_data['pos'] == pos_top[2]]['cuenta'], name = pos_top[2], width = 18, marker = dict(color = colors[2])),
        go.Barpolar(theta = [angle*1], r = artist_data[artist_data['pos'] == pos_top[1]]['cuenta'], name = pos_top[1], width = 18, marker = dict(color = colors[3])),
        go.Barpolar(theta = [angle*0], r = artist_data[artist_data['pos'] == pos_top[0]]['cuenta'], name = pos_top[0], width = 18, marker = dict(color = colors[4])),   
        ]
    )


    # angular axis
    fig_artist.layout.polar.angularaxis.showline = False
    fig_artist.layout.polar.angularaxis.showgrid = False
    fig_artist.layout.polar.angularaxis.rotation = 9
    fig_artist.layout.polar.angularaxis.showticklabels = False
    fig_artist.layout.polar.angularaxis.ticklen = 0

    # radial axis
    fig_artist.layout.polar.radialaxis.showgrid = False
    fig_artist.layout.polar.radialaxis.showline = True
    fig_artist.layout.polar.radialaxis.ticklen = 10
    fig_artist.layout.polar.radialaxis.tickformat = 's'
    fig_artist.layout.polar.radialaxis.nticks = 5
    fig_artist.layout.polar.radialaxis.tickfont.size = 28
    fig_artist.layout.polar.radialaxis.tickangle = 90
    fig_artist.layout.polar.radialaxis.ticksuffix = ' palabras'
    fig_artist.layout.polar.radialaxis.range = [1, artist_data['cuenta'].max() + (artist_data['cuenta'].max() % 50)]

    # hole
    fig_artist.layout.polar.hole = 0.5

    # size
    fig_artist.layout.width = 1200
    fig_artist.layout.height = 800

    # legend
    fig_artist.layout.legend.x = .5
    fig_artist.layout.legend.y = .95
    fig_artist.layout.legend.xanchor = 'center'
    fig_artist.layout.legend.font.size = 24
    fig_artist.layout.legend.orientation = 'h'

    # details
    fig_artist.layout.font.family = "Arial"
    fig_artist.layout.title = f'{artist}'
    
    fig_artist
    
    return fig_artist
make_chart(dataframe = df, artist='Residente')
make_chart(dataframe = df, artist='Canserbero')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16294277929155312, 'fraction_numerical': 0.03160762942779292, 'mean_word_length': 3.3964071856287426, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '482048', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1467, 'n_tokens_neox': 1355, 'n_words': 238, 'path': "#100Viz/12 - Rappin' LATAM/notebooks/12 Reppin LATAM.ipynb", 'repo_name': 'Chekos/-100Viz', 'size': '3670'}