1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
def creer_graphique(statistiques, timestamps_courant_ms, serie_temporelle_courant, type_graphique):
if not statistiques:
print("Impossible de generer le graphique: aucune donnee a afficher.")
return
texte_resume = (
"--- Resume de la Capture ---\n"
"Duree: %d s\n\n"
"Tension Min: %.3f V\n"
"Tension Max: %.3f V\n"
"Tension Moy: %.3f V\n\n"
"Courant Min: %.2f uA\n"
"Courant Max: %.2f uA\n"
"Courant Moy: %.2f uA"
) % (
statistiques["duree_capture_sec"],
statistiques["tension_min"],
statistiques["tension_max"],
statistiques["tension_moyenne"],
statistiques["courant_min"],
statistiques["courant_max"],
statistiques["courant_moyen"]
)
print("\n" + texte_resume)
plt.figure(figsize=(12, 7))
if type_graphique == "bar":
plt.bar(timestamps_courant_ms, serie_temporelle_courant)
else:
plt.plot(timestamps_courant_ms, serie_temporelle_courant)
plt.title('Analyse de Consommation (Banc de test INA226)', fontsize=16)
plt.xlabel('Temps (millisecondes)', fontsize=12)
plt.ylabel('Courant (uA) - Echelle Logarithmique', fontsize=12)
plt.yscale('log')
plt.grid(True, which="both", linestyle='--', linewidth=0.5)
courant_min_stat = statistiques["courant_min"]
courant_max_stat = statistiques["courant_max"]
if courant_min_stat <= 0:
courant_min_stat = 1
y_lim_min = courant_min_stat * 0.9
y_lim_max = courant_max_stat * 1.1
plt.ylim(y_lim_min, y_lim_max)
position_x = plt.xlim()[1] * 0.05
position_y = statistiques["courant_max"] / 4.0
plt.text(
position_x, position_y, texte_resume,
fontdict={'family': 'monospace', 'color': 'darkblue', 'size': 10},
bbox=dict(boxstyle='round,pad=0.5', fc='aliceblue', alpha=0.8)
)
plt.tight_layout()
plt.show() |
Partager