swarmauri_tool_matplotlib 0.6.0.dev154__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- swarmauri_tool_matplotlib/MatplotlibCsvTool.py +78 -0
- swarmauri_tool_matplotlib/MatplotlibTool.py +120 -0
- swarmauri_tool_matplotlib/__init__.py +17 -0
- swarmauri_tool_matplotlib-0.6.0.dev154.dist-info/METADATA +20 -0
- swarmauri_tool_matplotlib-0.6.0.dev154.dist-info/RECORD +7 -0
- swarmauri_tool_matplotlib-0.6.0.dev154.dist-info/WHEEL +4 -0
- swarmauri_tool_matplotlib-0.6.0.dev154.dist-info/entry_points.txt +4 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import pandas as pd
|
|
2
|
+
import matplotlib.pyplot as plt
|
|
3
|
+
import base64
|
|
4
|
+
from typing import List, Literal, Dict
|
|
5
|
+
from pydantic import Field
|
|
6
|
+
from swarmauri_standard.tools.Parameter import Parameter
|
|
7
|
+
from swarmauri_base.tools.ToolBase import ToolBase
|
|
8
|
+
from swarmauri_core.ComponentBase import ComponentBase
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@ComponentBase.register_type(ToolBase, "MatplotlibCsvTool")
|
|
12
|
+
class MatplotlibCsvTool(ToolBase):
|
|
13
|
+
type: Literal["MatplotlibCsvTool"] = "MatplotlibCsvTool"
|
|
14
|
+
name: str = Field(
|
|
15
|
+
"MatplotlibCsvTool",
|
|
16
|
+
description="Tool to generate plots from CSV data using Matplotlib.",
|
|
17
|
+
)
|
|
18
|
+
description: str = Field(
|
|
19
|
+
"This tool reads data from a CSV file and generates a plot using Matplotlib.",
|
|
20
|
+
description="Description of the MatplotlibCsvTool",
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
parameters: List[Parameter] = Field(
|
|
24
|
+
default_factory=lambda: [
|
|
25
|
+
Parameter(
|
|
26
|
+
name="csv_file",
|
|
27
|
+
type="string",
|
|
28
|
+
description="The path to the CSV file containing the data.",
|
|
29
|
+
required=True,
|
|
30
|
+
),
|
|
31
|
+
Parameter(
|
|
32
|
+
name="x_column",
|
|
33
|
+
type="string",
|
|
34
|
+
description="The name of the column to use for the x-axis.",
|
|
35
|
+
required=True,
|
|
36
|
+
),
|
|
37
|
+
Parameter(
|
|
38
|
+
name="y_column",
|
|
39
|
+
type="string",
|
|
40
|
+
description="The name of the column to use for the y-axis.",
|
|
41
|
+
required=True,
|
|
42
|
+
),
|
|
43
|
+
Parameter(
|
|
44
|
+
name="output_file",
|
|
45
|
+
type="string",
|
|
46
|
+
description="The filename where the plot will be saved.",
|
|
47
|
+
required=True,
|
|
48
|
+
),
|
|
49
|
+
]
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
def __call__(
|
|
53
|
+
self, csv_file: str, x_column: str, y_column: str, output_file: str
|
|
54
|
+
) -> Dict[str, str]:
|
|
55
|
+
# Read data from CSV
|
|
56
|
+
data = pd.read_csv(csv_file)
|
|
57
|
+
|
|
58
|
+
# Check if columns exist in the DataFrame
|
|
59
|
+
if x_column not in data.columns or y_column not in data.columns:
|
|
60
|
+
raise ValueError(
|
|
61
|
+
f"Columns {x_column} and/or {y_column} not found in the CSV file."
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
# Generate plot
|
|
65
|
+
plt.figure(figsize=(10, 6))
|
|
66
|
+
plt.plot(data[x_column], data[y_column], marker="o")
|
|
67
|
+
plt.xlabel(x_column)
|
|
68
|
+
plt.ylabel(y_column)
|
|
69
|
+
plt.title(f"{y_column} vs {x_column}")
|
|
70
|
+
plt.grid(True)
|
|
71
|
+
plt.savefig(output_file)
|
|
72
|
+
plt.close()
|
|
73
|
+
print(f"Plot generated and saved to {output_file}")
|
|
74
|
+
# Encode the plot image as base64
|
|
75
|
+
with open(output_file, "rb") as image_file:
|
|
76
|
+
encoded_image = base64.b64encode(image_file.read()).decode("utf-8")
|
|
77
|
+
|
|
78
|
+
return {"img_path": output_file, "img_base64": encoded_image, "data": []}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import base64
|
|
2
|
+
import matplotlib.pyplot as plt
|
|
3
|
+
from typing import List, Literal
|
|
4
|
+
from pydantic import Field
|
|
5
|
+
from swarmauri_base.tools.ToolBase import ToolBase
|
|
6
|
+
from swarmauri_standard.tools.Parameter import Parameter
|
|
7
|
+
from swarmauri_core.ComponentBase import ComponentBase
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@ComponentBase.register_type(ToolBase, "MatplotlibTool")
|
|
11
|
+
class MatplotlibTool(ToolBase):
|
|
12
|
+
version: str = "1.0.0"
|
|
13
|
+
name: str = "MatplotlibTool"
|
|
14
|
+
description: str = (
|
|
15
|
+
"Generates a plot using Matplotlib library based on provided configuration."
|
|
16
|
+
)
|
|
17
|
+
type: Literal["MatplotlibTool"] = "MatplotlibTool"
|
|
18
|
+
|
|
19
|
+
parameters: List[Parameter] = Field(
|
|
20
|
+
default_factory=lambda: [
|
|
21
|
+
Parameter(
|
|
22
|
+
name="plot_type",
|
|
23
|
+
type="string",
|
|
24
|
+
description="Type of plot to generate (e.g., 'line', 'bar', 'scatter').",
|
|
25
|
+
required=True,
|
|
26
|
+
enum=["line", "bar", "scatter"],
|
|
27
|
+
),
|
|
28
|
+
Parameter(
|
|
29
|
+
name="x_data",
|
|
30
|
+
type="list<float>",
|
|
31
|
+
description="X-axis data for the plot.",
|
|
32
|
+
required=True,
|
|
33
|
+
),
|
|
34
|
+
Parameter(
|
|
35
|
+
name="y_data",
|
|
36
|
+
type="list<float>",
|
|
37
|
+
description="Y-axis data for the plot.",
|
|
38
|
+
required=True,
|
|
39
|
+
),
|
|
40
|
+
Parameter(
|
|
41
|
+
name="title",
|
|
42
|
+
type="string",
|
|
43
|
+
description="Title of the plot.",
|
|
44
|
+
required=False,
|
|
45
|
+
default="",
|
|
46
|
+
),
|
|
47
|
+
Parameter(
|
|
48
|
+
name="x_label",
|
|
49
|
+
type="string",
|
|
50
|
+
description="Label for the X-axis.",
|
|
51
|
+
required=False,
|
|
52
|
+
default="",
|
|
53
|
+
),
|
|
54
|
+
Parameter(
|
|
55
|
+
name="y_label",
|
|
56
|
+
type="string",
|
|
57
|
+
description="Label for the Y-axis.",
|
|
58
|
+
required=False,
|
|
59
|
+
default="",
|
|
60
|
+
),
|
|
61
|
+
Parameter(
|
|
62
|
+
name="save_path",
|
|
63
|
+
type="string",
|
|
64
|
+
description="Path to save the generated plot image.",
|
|
65
|
+
required=False,
|
|
66
|
+
default="plot.png",
|
|
67
|
+
),
|
|
68
|
+
]
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
def __call__(
|
|
72
|
+
self,
|
|
73
|
+
plot_type: str,
|
|
74
|
+
x_data: List[float],
|
|
75
|
+
y_data: List[float],
|
|
76
|
+
title: str = "",
|
|
77
|
+
x_label: str = "",
|
|
78
|
+
y_label: str = "",
|
|
79
|
+
save_path: str = "plot.png",
|
|
80
|
+
):
|
|
81
|
+
"""
|
|
82
|
+
Generates a plot using Matplotlib based on provided configuration.
|
|
83
|
+
|
|
84
|
+
Parameters:
|
|
85
|
+
plot_type (str): The type of the plot ('line', 'bar', 'scatter').
|
|
86
|
+
x_data (List[float]): X-axis data for the plot.
|
|
87
|
+
y_data (List[float]): Y-axis data for the plot.
|
|
88
|
+
title (str): Title of the plot.
|
|
89
|
+
x_label (str): Label for the X-axis.
|
|
90
|
+
y_label (str): Label for the Y-axis.
|
|
91
|
+
save_path (str): Path to save the generated plot image.
|
|
92
|
+
|
|
93
|
+
Returns:
|
|
94
|
+
str: Path where the plot image is saved.
|
|
95
|
+
"""
|
|
96
|
+
plt.figure()
|
|
97
|
+
|
|
98
|
+
if plot_type == "line":
|
|
99
|
+
plt.plot(x_data, y_data)
|
|
100
|
+
elif plot_type == "bar":
|
|
101
|
+
plt.bar(x_data, y_data)
|
|
102
|
+
elif plot_type == "scatter":
|
|
103
|
+
plt.scatter(x_data, y_data)
|
|
104
|
+
else:
|
|
105
|
+
raise ValueError(f"Unsupported plot type: {plot_type}")
|
|
106
|
+
|
|
107
|
+
if title:
|
|
108
|
+
plt.title(title)
|
|
109
|
+
if x_label:
|
|
110
|
+
plt.xlabel(x_label)
|
|
111
|
+
if y_label:
|
|
112
|
+
plt.ylabel(y_label)
|
|
113
|
+
|
|
114
|
+
plt.savefig(save_path)
|
|
115
|
+
plt.close()
|
|
116
|
+
|
|
117
|
+
with open(save_path, "rb") as image_file:
|
|
118
|
+
encoded_image = base64.b64encode(image_file.read()).decode("utf-8")
|
|
119
|
+
|
|
120
|
+
return {"img_path": save_path, "img_base64": encoded_image, "data": []}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
from .MatplotlibCsvTool import MatplotlibCsvTool
|
|
2
|
+
from .MatplotlibTool import MatplotlibTool
|
|
3
|
+
|
|
4
|
+
__version__ = "0.6.0.dev26"
|
|
5
|
+
__long_desc__ = """
|
|
6
|
+
|
|
7
|
+
# Swarmauri Matplotlib Based Components
|
|
8
|
+
|
|
9
|
+
Components Included:
|
|
10
|
+
- MatplotlibTool
|
|
11
|
+
- MatplotlibCsvTool
|
|
12
|
+
|
|
13
|
+
Visit us at: https://swarmauri.com
|
|
14
|
+
Follow us at: https://github.com/swarmauri
|
|
15
|
+
Star us at: https://github.com/swarmauri/swarmauri-sdk
|
|
16
|
+
|
|
17
|
+
"""
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: swarmauri_tool_matplotlib
|
|
3
|
+
Version: 0.6.0.dev154
|
|
4
|
+
Summary: Matplotlib tool for Swarmauri.
|
|
5
|
+
License: Apache-2.0
|
|
6
|
+
Author: Jacob Stewart
|
|
7
|
+
Author-email: jacob@swarmauri.com
|
|
8
|
+
Requires-Python: >=3.10,<3.13
|
|
9
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Requires-Dist: matplotlib (>=3.9.2)
|
|
15
|
+
Requires-Dist: swarmauri_base (>=0.6.0.dev154,<0.7.0)
|
|
16
|
+
Requires-Dist: swarmauri_core (>=0.6.0.dev154,<0.7.0)
|
|
17
|
+
Project-URL: Repository, http://github.com/swarmauri/swarmauri-sdk
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
|
|
20
|
+
# Swarmauri Example Plugin
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
swarmauri_tool_matplotlib/__init__.py,sha256=-XoJFJx5cFxk5fRyhcf3K-c7HYbwzbW7ZVWOuw9dHa0,397
|
|
2
|
+
swarmauri_tool_matplotlib/MatplotlibCsvTool.py,sha256=kkK4eNC-MGO2owjvqs_-T0p4GVf-7wh-vL5ogTfWkmc,2839
|
|
3
|
+
swarmauri_tool_matplotlib/MatplotlibTool.py,sha256=neD2KhGxFRRjEvbO0ACgjwESoGPteIMO1diZNfqCZqk,3912
|
|
4
|
+
swarmauri_tool_matplotlib-0.6.0.dev154.dist-info/entry_points.txt,sha256=tmpuKPgEx3MrpElcuhj5RAC42feLuh9TzDRC7Vz1ftQ,137
|
|
5
|
+
swarmauri_tool_matplotlib-0.6.0.dev154.dist-info/METADATA,sha256=BJEh18bxKFPYH8a4iPCSraC0lTwVUw-hZQJ7ge8bAqg,765
|
|
6
|
+
swarmauri_tool_matplotlib-0.6.0.dev154.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
|
|
7
|
+
swarmauri_tool_matplotlib-0.6.0.dev154.dist-info/RECORD,,
|