feliponi commited on
Commit
fb60860
·
1 Parent(s): 0c70d54

Ajuste do grafico

Browse files
Files changed (2) hide show
  1. __pycache__/stocks.cpython-311.pyc +0 -0
  2. app.py +24 -7
__pycache__/stocks.cpython-311.pyc CHANGED
Binary files a/__pycache__/stocks.cpython-311.pyc and b/__pycache__/stocks.cpython-311.pyc differ
 
app.py CHANGED
@@ -217,17 +217,34 @@ class GradioInterface:
217
 
218
 
219
  def generate_simple_plot(self, bt_integration):
220
- # Implemente aqui a geração do gráfico usando matplotlib
221
  import matplotlib.pyplot as plt
 
 
 
 
 
 
 
 
 
 
 
 
 
222
 
223
- plt.figure(figsize=(10, 6))
224
- # Exemplo: Plotar preço de fechamento
225
- data = bt_integration.cerebro.datas[0].close.array
226
- plt.plot(data, label='Preço')
227
- plt.title("Desempenho Histórico")
 
 
 
 
228
  plt.legend()
 
 
229
  return plt.gcf()
230
-
231
  # Configuração da interface completa
232
  pipeline = st.AnalysisPipeline()
233
 
 
217
 
218
 
219
  def generate_simple_plot(self, bt_integration):
 
220
  import matplotlib.pyplot as plt
221
+ import matplotlib.dates as mdates
222
+
223
+ plt.figure(figsize=(12, 6))
224
+
225
+ # Get data feed from Backtrader
226
+ datafeed = bt_integration.cerebro.datas[0]
227
+
228
+ # Extract dates and closing prices
229
+ dates = [datetime.fromordinal(int(date)) for date in datafeed.datetime.array]
230
+ closes = datafeed.close.array
231
+
232
+ # Plot
233
+ plt.plot(dates, closes, label='Preço de Fechamento', linewidth=1.5)
234
 
235
+ # Format dates
236
+ plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m'))
237
+ plt.gca().xaxis.set_major_locator(mdates.MonthLocator(interval=3))
238
+ plt.gcf().autofmt_xdate() # Rotate dates
239
+
240
+ # Add labels and grid
241
+ plt.title("Desempenho Histórico - Evolução do Preço")
242
+ plt.xlabel("Data")
243
+ plt.ylabel("Preço (USD)")
244
  plt.legend()
245
+ plt.grid(True, alpha=0.3)
246
+
247
  return plt.gcf()
 
248
  # Configuração da interface completa
249
  pipeline = st.AnalysisPipeline()
250