-
Notifications
You must be signed in to change notification settings - Fork 0
/
visualize.py
95 lines (72 loc) · 2.5 KB
/
visualize.py
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#%matplotlib notebook
#%matplotlib inline
import matplotlib.pyplot as plt
plt.rcParams['figure.figsize'] = (18, 12)
def price(x):
"""
format the coords message box
:param x: data to be formatted
:return: formatted data
"""
return '$%1.2f' % x
def plot_basic(stocks, title='Google Trading', y_label='Price USD', x_label='Trading Days'):
"""
Plots basic pyplot
:param stocks: DataFrame having all the necessary data
:param title: Title of the plot
:param y_label: yLabel of the plot
:param x_label: xLabel of the plot
:return: prints a Pyplot againts items and their closing value
"""
fig, ax = plt.subplots()
ax.plot(stocks['Item'], stocks['Close'], '#0A7388')
ax.format_ydata = price
ax.set_title(title)
# Add labels
plt.ylabel(y_label)
plt.xlabel(x_label)
plt.show()
def plot_prediction(actual, prediction, title='Google Trading vs Prediction', y_label='Price USD', x_label='Trading Days'):
"""
Plots train, test and prediction
:param actual: DataFrame containing actual data
:param prediction: DataFrame containing predicted values
:param title: Title of the plot
:param y_label: yLabel of the plot
:param x_label: xLabel of the plot
:return: prints a Pyplot againts items and their closing value
"""
fig = plt.figure()
ax = fig.add_subplot(111)
# Add labels
plt.ylabel(y_label)
plt.xlabel(x_label)
# Plot actual and predicted close values
plt.plot(actual, '#00FF00', label='Adjusted Close')
plt.plot(prediction, '#0000FF', label='Predicted Close')
# Set title
ax.set_title(title)
ax.legend(loc='upper left')
plt.show()
def plot_lstm_prediction(actual, prediction, title='Google Trading vs Prediction', y_label='Price USD', x_label='Trading Days'):
"""
Plots train, test and prediction
:param actual: DataFrame containing actual data
:param prediction: DataFrame containing predicted values
:param title: Title of the plot
:param y_label: yLabel of the plot
:param x_label: xLabel of the plot
:return: prints a Pyplot againts items and their closing value
"""
fig = plt.figure()
ax = fig.add_subplot(111)
# Add labels
plt.ylabel(y_label)
plt.xlabel(x_label)
# Plot actual and predicted close values
plt.plot(actual, '#00FF00', label='Adjusted Close')
plt.plot(prediction, '#0000FF', label='Predicted Close')
# Set title
ax.set_title(title)
ax.legend(loc='upper left')
plt.show()