import pandas as pd import matplotlib.pyplot as plt from pathlib import Path folder = Path(__file__).parent files = sorted(folder.glob("*_ultimo_ciclo.csv")) # categorical palette (light mode), fixed order colors = ["#2a78d6", "#1baf7a", "#eda100", "#e34948"] combined = {} series = [] for f in files: df = pd.read_csv(f, sep=";", decimal=",") label = f.stem.replace(" soluzione (-1.6_1.2", "").replace(")_ultimo_ciclo", "").replace("_ultimo_ciclo", "") label = label.replace("AL7 10 mgml", "").strip() if not label.lower().startswith("scan"): label = "scan " + label.split("scan")[-1].strip() if "scan" in label else label c = df.iloc[:, 2] # column C: Potential normalized/V e = df.iloc[:, 4] # column E: last column combined[f"{label} - Potential normalized/V"] = c.reset_index(drop=True) combined[f"{label} - {df.columns[4]}"] = e.reset_index(drop=True) series.append((label, c, e)) out_df = pd.concat(combined, axis=1) out_csv = folder / "combined_C_E.csv" out_df.to_csv(out_csv, sep=";", decimal=",", index=False) print(f"Saved {out_csv}") fig, ax = plt.subplots(figsize=(9, 6), dpi=150) fig.patch.set_facecolor("#fcfcfb") ax.set_facecolor("#fcfcfb") for i, (label, c, e) in enumerate(series): ax.plot(c, e, label=label, color=colors[i % len(colors)], linewidth=2) ax.set_xlabel("Potential normalized / V", color="#0b0b0b") ax.set_ylabel("Current / sqrt(scan rate) / scan rate", color="#0b0b0b") ax.set_title("Confronto cicli - Potenziale normalizzato vs ultima colonna", color="#0b0b0b") ax.tick_params(colors="#52514e") ax.grid(True, color="#e1e0d9", linewidth=0.8) for spine in ax.spines.values(): spine.set_color("#c3c2b7") legend = ax.legend(frameon=False, labelcolor="#0b0b0b") out_png = folder / "combined_plot.png" fig.savefig(out_png, facecolor=fig.get_facecolor()) print(f"Saved {out_png}")