-
Notifications
You must be signed in to change notification settings - Fork 0
/
graphing.py
142 lines (116 loc) · 4.84 KB
/
graphing.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import matplotlib.pyplot as plt
import plotly.graph_objects as go
import numpy as np
import pandas as pd
from rich.table import Table
from rich import print
""""""""" Single Asset Graphing """""""""""
def graph(price_array, time_array, graphtitle = "Price of asset over time", yaxistitle = 'Price (USD)', xaxistitle = 'Time (Months)'):
""" First parameter is for the price array and the second is for the time array"""
#Creates the figure under the graphtitle name
fig = plt.figure(graphtitle)
#sets the background of the plot to trasparent
fig.patch.set_alpha(0.0)
ax = plt.axes()
ax.patch.set_alpha(0.0)
#sets up the graph and displays it to the screen in the figure
plt.title(graphtitle)
plt.plot(price_array, time_array)
plt.ylabel(yaxistitle)
plt.xlabel(xaxistitle)
print("[bold purple][Displaying\t][/bold purple] graph")
print(f"[bold yellow][Title:\t\t][/bold yellow] {graphtitle}")
plt.show()
print("[bold red][Exiting\t][/bold red] graph\n")
""""""""" Multiple Assets Graphing """""""""""
def subcompare(assets_array, subplot_title = "The prices over time:", yaxistitle = 'Price (USD)', xaxistitle = 'Time (Months)'):
"""Compares multiple assets in one price over time graph. (Parameter: Expects a Matrix)"""
number_of_assets = len(assets_array[0])
#Dynamically creates the title and adds in all the assets to it
title_array = [subplot_title]
for assets_name in assets_array[0]:
title_array.append(assets_name)
title = pd.Series(title_array)
title = title.str.cat(sep=" ")
#creates new transparent figure and inputs the title
fig = plt.figure(title)
fig.patch.set_alpha(0.0)
plt.title(title)
#dynamically determine which subplot figuration is best based on the number of assets
if(number_of_assets % 2 == 0 and number_of_assets >= 4):
#dynamically subplots the data xs then ys in a nested for loop
num_of_rows = int(number_of_assets / 2)
num_of_cols = int(number_of_assets / 2)
for i in range(number_of_assets):
ax = plt.subplot(num_of_rows, num_of_cols, i + 1)
#sets the background of the plot to trasparent
ax.patch.set_alpha(0.0)
plt.title(assets_array[0][i])
plt.ylabel(yaxistitle)
plt.xlabel(xaxistitle)
plt.plot(assets_array[1][i], assets_array[2][i])
else:
#dynamically subplots the data xs then ys in a nested for loop
num_of_rows = number_of_assets
for i in range(number_of_assets):
ax = plt.subplot(num_of_rows, 1, i + 1)
#sets the background of the plot to trasparent
ax.patch.set_alpha(0.0)
plt.title(assets_array[0][i])
plt.ylabel(yaxistitle)
plt.xlabel(xaxistitle)
plt.plot(assets_array[1][i], assets_array[2][i])
#displays the plot
print("[bold purple][Displaying\t][/bold purple] subcompare graph")
print(f"[bold yellow][Title\t\t][/bold yellow] {title}")
plt.show()
print("[bold red][Exiting\t][/bold red] subcompare graph\n")
def figcompare(assets_array, figure_title = "The prices over time:\n", yaxistitle = 'Price (USD)', xaxistitle = 'Time (Months)'):
"""Compares multiple assets in multiple price over time graph. (Parameter: Expects a Matrix)"""
number_of_assets = len(assets_array[0])
#Dynamically creates the title and adds in all the assets to it
title_array = [figure_title]
count = 0
for assets_name in assets_array[0]:
title = figure_title + " " + assets_name
#creates new transparent figure and inputs the title
fig = plt.figure(title)
fig.patch.set_alpha(0.0)
ax = plt.axes()
ax.patch.set_alpha(0.0)
plt.title(title)
plt.ylabel(yaxistitle)
plt.xlabel(xaxistitle)
plt.plot(assets_array[1][count], assets_array[2][count])
count = count + 1
#displays the plot
print("[bold purple][Displaying\t][/bold purple] figcompare graph")
print(f"[bold yellow][Title\t\t][/bold yellow] {title}")
plt.show()
print("[bold red][Exiting\t][/bold red] figcompare graph\n")
def graphcompare(assets_array, figure_title = "The prices over time:\n", yaxistitle = 'Price (USD)', xaxistitle = 'Time (Months)'):
"""Compares multiple assets in one price over time graph. (Parameter: Expects a Matrix)"""
number_of_assets = len(assets_array[0])
#Dynamically creates the title and adds in all the assets to it
title_array = [figure_title]
for assets_name in assets_array[0]:
title_array.append(assets_name)
title = pd.Series(title_array)
title = title.str.cat(sep=" ")
#creates new transparent figure and inputs the title
fig = plt.figure(title)
fig.patch.set_alpha(0.0)
ax = plt.axes()
ax.patch.set_alpha(0.0)
plt.title(title)
plt.ylabel(yaxistitle)
plt.xlabel(xaxistitle)
for i in range(number_of_assets):
asset_name = assets_array[0][i]
plt.plot(assets_array[1][i], assets_array[2][i], label = asset_name)
#displays the plot
plt.legend(loc=2)
print("[bold purple][Displaying\t][/bold purple] graphcompare graph")
print(f"[bold yellow][Title\t\t][/bold yellow] {title}")
plt.show()
print("[bold red][Exiting\t][/bold red] graphcompare graph\n")