Enoder commited on
Commit
3d6d83e
·
verified ·
1 Parent(s): 38c0eeb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -6
app.py CHANGED
@@ -41,6 +41,9 @@ def create_graph(prices_history):
41
  fig, axs = plt.subplots(nrows=2, ncols=2, figsize=(15, 10))
42
  axs = axs.flatten()
43
 
 
 
 
44
  for ax, (coin, prices) in zip(axs, prices_history.items()):
45
  if prices:
46
  times, price_values = zip(*prices)
@@ -56,7 +59,16 @@ def create_graph(prices_history):
56
  ax.grid()
57
  ax.legend()
58
 
 
 
 
 
 
 
 
 
59
  plt.tight_layout()
 
60
  plt.savefig('crypto_prices_rectangle.png')
61
  plt.close()
62
 
@@ -81,12 +93,6 @@ def run_script():
81
  send_to_discord(prices, 'crypto_prices_rectangle.png')
82
 
83
  st.image('crypto_prices_rectangle.png')
84
-
85
- # Affichage des prix actuels sous chaque graphique
86
- for coin, prices in prices_history.items():
87
- if prices:
88
- current_price = prices[-1][1]
89
- st.write(f"Prix actuel de {coin.capitalize()}: ${current_price:.2f}")
90
 
91
  st.success("Graphique créé et envoyé à Discord!")
92
 
 
41
  fig, axs = plt.subplots(nrows=2, ncols=2, figsize=(15, 10))
42
  axs = axs.flatten()
43
 
44
+ # Pour afficher les prix actuels sous chaque graphique
45
+ current_prices = {}
46
+
47
  for ax, (coin, prices) in zip(axs, prices_history.items()):
48
  if prices:
49
  times, price_values = zip(*prices)
 
59
  ax.grid()
60
  ax.legend()
61
 
62
+ # On récupère le dernier prix de la crypto pour l'afficher en bas
63
+ current_prices[coin] = price_values[-1]
64
+
65
+ # Ajouter une légende en bas de l'image avec les prix actuels
66
+ plt.figtext(0.5, 0.01, 'Prix actuel de chaque crypto-monnaie (en USD):\n', ha='center', fontsize=12)
67
+ for i, (coin, price) in enumerate(current_prices.items()):
68
+ plt.figtext(0.5, 0.01 - (i + 1) * 0.04, f'{coin.capitalize()}: ${price:.2f}', ha='center', fontsize=10)
69
+
70
  plt.tight_layout()
71
+ plt.subplots_adjust(bottom=0.1) # Ajuste le bas pour faire de la place pour la légende
72
  plt.savefig('crypto_prices_rectangle.png')
73
  plt.close()
74
 
 
93
  send_to_discord(prices, 'crypto_prices_rectangle.png')
94
 
95
  st.image('crypto_prices_rectangle.png')
 
 
 
 
 
 
96
 
97
  st.success("Graphique créé et envoyé à Discord!")
98