Untitled

 avatar
unknown
plain_text
2 years ago
2.0 kB
5
Indexable
def plot_selection_barplot_segregado(df, nombre, nombre_compania, agrupation):

    plt.figure(figsize=(18, 10))

    my_palette = sns.color_palette(["#FFD779","#FFC12A",'#F2A337', '#EA832F', '#D77423', '#C05E1A'], n_colors=6)

    #Paleta saturada
    #my_palette2 = sns.color_palette(["#00495E","#FF9E01",'#52D0B7', '#00B050', '#B50042'], n_colors=4)
    
    #hue_order = ['Directivos', 'Administrativos', 'Técnicos']
    
    sns.set(context="paper", font_scale=1.2)  # Adjust the font_scale value as needed
    
    sns.set_style("whitegrid")  # Set the style to "whitegrid"
    
    ax = sns.barplot(x = "TEMA", y = "RESPUESTA", hue = agrupation,  data = df, palette=my_palette) # , hue_order=hue_order ,  width=0.8
    
    # Ejecutar dos veces si los colectivos no tienen los mismos ejercicios: No user "hue_order" cuando no están todas las categorías en el gráfico

    for container in ax.containers:
        ax.bar_label(container)

    ax.set_ylim(0,4.5)

    plt.title(nombre)
    
    plt.legend(loc='upper center', bbox_to_anchor=(0.5, -0.1), ncol=2)
    
    plt.savefig(nombre_compania + "_" + nombre + '.jpg', bbox_inches='tight', dpi=200)

    #plt.show()

def get_selection_chart_segregado(df_agrupation, agrupation): #, modulo
    
    df_selection = df_agrupation[df_agrupation['TIPO_PREGUNTA'] == 'selection']
    
    df_selection["RESPUESTA"] = df_selection["RESPUESTA"].astype('int')

    result = df_selection.groupby(["EJERCICIO", "TEMA", agrupation])["RESPUESTA"].mean()

    result_df = result.to_frame().reset_index()
    result_df["RESPUESTA"] = result_df["RESPUESTA"].apply(lambda x: round(x,2))

    for ejercicio in result_df["EJERCICIO"].unique():
        df_ejercicio = result_df[result_df["EJERCICIO"] == ejercicio]
        plot_selection_barplot_segregado(df_ejercicio, ejercicio, orquestador.nombre_compania, agrupation)


get_selection_chart_segregado(df_rivera_analytics, "Empresa") # , 'Módulo 3: Inteligencia Transversal'
Editor is loading...