Lar159 commited on
Commit
6819f29
·
verified ·
1 Parent(s): 9e67260

Update tools/statistical_graph_generator.py

Browse files
tools/statistical_graph_generator.py CHANGED
@@ -4,6 +4,38 @@ from smolagents.tools import tool
4
  import time
5
  from typing import List, Dict
6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  @tool
8
  def plot_bar_chart(labels: List[str], values: List[float], title: str = "Gráfico de Barras", x_label: str = "Categorias", y_label: str = "Valores") -> str:
9
  """
 
4
  import time
5
  from typing import List, Dict
6
 
7
+
8
+ def plot_line_chart(x_values: List, y_values: List[float], title: str = "Gráfico de Linhas", x_label: str = "Eixo X", y_label: str = "Eixo Y") -> str:
9
+ """
10
+ Gera e salva um gráfico de linhas, ideal para mostrar tendências ao longo do tempo.
11
+ Args:
12
+ x_values: Uma lista de rótulos ou números para o eixo X (ex: meses, anos).
13
+ y_values: Uma lista de números (int ou float) para o eixo Y.
14
+ title: O título do gráfico.
15
+ x_label: O rótulo do eixo X.
16
+ y_label: O rótulo do eixo Y.
17
+ Returns:
18
+ O caminho do arquivo da imagem PNG gerada.
19
+ """
20
+ try:
21
+ if len(x_values) != len(y_values):
22
+ return "Erro: As listas x_values e y_values devem ter o mesmo tamanho."
23
+
24
+ plt.figure(figsize=(10, 6))
25
+ plt.plot(x_values, y_values, marker='o', linestyle='-')
26
+ plt.title(title)
27
+ plt.xlabel(x_label)
28
+ plt.ylabel(y_label)
29
+ plt.grid(True, which='both', linestyle='--', linewidth=0.5)
30
+ plt.tight_layout()
31
+
32
+ file_path = f"line_chart_{int(time.time())}.png"
33
+ plt.savefig(file_path)
34
+ plt.close()
35
+
36
+ return f"Gráfico de linhas gerado e salvo em: {file_path}"
37
+ except Exception as e:
38
+ return f"Erro ao gerar o gráfico de linhas: {str(e)}"
39
  @tool
40
  def plot_bar_chart(labels: List[str], values: List[float], title: str = "Gráfico de Barras", x_label: str = "Categorias", y_label: str = "Valores") -> str:
41
  """