mgbam commited on
Commit
b8b8eab
·
verified ·
1 Parent(s): 36a5c35

Update tools/plot_generator.py

Browse files
Files changed (1) hide show
  1. tools/plot_generator.py +22 -11
tools/plot_generator.py CHANGED
@@ -1,14 +1,25 @@
1
-
2
  import pandas as pd
3
- import matplotlib.pyplot as plt
4
 
5
- def plot_sales_tool(file_path: str) -> str:
 
 
 
 
6
  df = pd.read_csv(file_path)
7
- if 'Month' not in df.columns or 'Sales' not in df.columns:
8
- return "Missing 'Month' or 'Sales' columns."
9
- plt.figure(figsize=(10, 6))
10
- plt.plot(df['Month'], df['Sales'], marker='o')
11
- plt.xticks(rotation=45)
12
- plt.title("Sales Trend")
13
- plt.savefig("sales_plot.png")
14
- return "Generated sales_plot.png"
 
 
 
 
 
 
 
 
 
 
1
  import pandas as pd
2
+ import plotly.graph_objects as go
3
 
4
+ def plot_sales_tool(file_path: str, date_col: str = "Month") -> str:
5
+ """
6
+ Builds an interactive Plotly line chart for Sales.
7
+ Saves a PNG fallback (sales_plot.png) for Streamlit thumbnail.
8
+ """
9
  df = pd.read_csv(file_path)
10
+
11
+ if date_col not in df.columns or "Sales" not in df.columns:
12
+ return f"❌ '{date_col}' or 'Sales' column missing."
13
+
14
+ fig = go.Figure(
15
+ go.Scatter(
16
+ x=df[date_col],
17
+ y=df["Sales"],
18
+ mode="lines+markers",
19
+ line=dict(width=2),
20
+ )
21
+ )
22
+ fig.update_layout(title="Sales Trend", template="plotly_dark")
23
+ fig.write_image("sales_plot.png") # still save for PNG fallback
24
+
25
+ return fig