From ede9cf278a5d97215c262929d4b9f29c3a928db3 Mon Sep 17 00:00:00 2001 From: Andrea Fiorencis Date: Mon, 23 Jun 2025 12:02:36 +0200 Subject: [PATCH] Generazione grafico da dataframe concentrato in una funzione --- Fotovoltaico.py | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/Fotovoltaico.py b/Fotovoltaico.py index 5f4127b..845865d 100644 --- a/Fotovoltaico.py +++ b/Fotovoltaico.py @@ -54,17 +54,18 @@ print("Valore massimo:",max(result_ac_energies_to_csv_df.gen_pv_100_kWp)) # prin print("Somma totale:",sum(result_ac_energies_to_csv_df.gen_pv_100_kWp)) # print the total sum of the generated energy result_ac_energies_to_csv_df.to_csv(path_export, encoding='utf-8') -# GENERAZIONE GRAFICO -import plotly.express as px -# Supponendo che la colonna di interesse sia 'gen_pv_100_kWp' -fig = px.line( - result_ac_energies_to_csv_df, - x=result_ac_energies_to_csv_df.index, - y='gen_pv_100_kWp', - title='Produttività Fotovoltaica nel Tempo', - labels={'gen_pv_100_kWp': 'Energia [kWh]', 'index': 'Data/Ora'} -) -fig.show() +def generate_grafico_df(dataframe): + # GENERAZIONE GRAFICO + import plotly.express as px + # Supponendo che la colonna di interesse sia 'gen_pv_100_kWp' + fig = px.line( + dataframe, + x=dataframe.index, + y='gen_pv_100_kWp', + title='Produttività Fotovoltaica nel Tempo', + labels={'gen_pv_100_kWp': 'Energia [kWh]', 'index': 'Data/Ora'} + ) + fig.show() def export_hourly_pv_productivity(result_ac_energies_to_csv_df, path_export_hourly): """ @@ -75,17 +76,6 @@ def export_hourly_pv_productivity(result_ac_energies_to_csv_df, path_export_hour df_hourly.to_csv(path_export_hourly, encoding='utf-8') print(f"File CSV orario salvato in: {path_export_hourly}") - fig = px.line( - df_hourly, - x=df_hourly.index, - y='gen_pv_100_kWp', - title='Produttività Fotovoltaica su Base Oraria', - labels={'gen_pv_100_kWp': 'Energia [kWh]', 'index': 'Data/Ora'} - ) - fig.show() - -# --- USO DELLA FUNZIONE DOPO L'EXPORT ORIGINALE --- - # Scegli il percorso per il nuovo file orario path_export_hourly = path_export.replace('.csv', '_hourly.csv')