-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_utils.py
More file actions
54 lines (38 loc) · 1.19 KB
/
plot_utils.py
File metadata and controls
54 lines (38 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import os
import matplotlib.pyplot as plt
import plotly.graph_objects as go
import config
def save_pattern_plot(pat, symbol, pattern_id):
"""
Save static PNG plot using matplotlib (reliable).
"""
df = pat["df"]
fig, ax = plt.subplots(figsize=(10, 6))
ax.plot(df["timestamp"], df["close"], label="Price", color="blue")
ax.set_title(f"Cup & Handle Pattern - {symbol} (ID {pattern_id})")
ax.legend()
filepath = os.path.join(config.PATTERNS_DIR, f"cup_handle_{pattern_id}.png")
plt.savefig(filepath)
plt.close(fig)
return filepath
def save_pattern_html(pat, symbol, pattern_id):
"""
Save interactive HTML plot using plotly.
"""
df = pat["df"]
fig = go.Figure()
fig.add_trace(go.Scatter(
x=df["timestamp"],
y=df["close"],
mode="lines",
name="Price"
))
fig.update_layout(
title=f"Cup & Handle Pattern - {symbol} (ID {pattern_id})",
xaxis_title="Time",
yaxis_title="Price",
template="plotly_white"
)
filepath = os.path.join(config.PATTERNS_DIR, f"cup_handle_{pattern_id}.html")
fig.write_html(filepath, include_plotlyjs="cdn")
return filepath