-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot.py
143 lines (129 loc) · 4.33 KB
/
plot.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
143
import plotly.express as px
import pandas as pd
import plotly.graph_objects as go
from plotly.subplots import make_subplots
def main_graph(df: pd.DataFrame):
fig = px.scatter(df,
x='risk_score',
y='return_score',
color="chain",
hover_data=["lp_name","protocol"],
labels={
"lp_name":"Liquidity Pool",
"return_score": "Return Score",
"risk_score": "Risk Score",
"chain": "Blockchain",
"protocol":"Protocol"
},
color_discrete_sequence=px.colors.qualitative.T10
)
fig.update_layout({
'plot_bgcolor': 'rgba(0, 0, 0, 0)',
'paper_bgcolor': 'rgba(0, 0, 0, 0)',
})
fig.update_traces(marker=dict(size=13,
line=dict(width=0.6,
color='DarkSlateGrey')),
selector=dict(mode='markers'))
fig.add_shape(type="line",
x0=0, y0=11, x1=0, y1=0,
line=dict(color="DarkSlateGrey",width=0.5)
)
fig.add_shape(type="line",
x0=0, y0=0, x1=10, y1=0,
line=dict(color="DarkSlateGrey",width=0.5)
)
fig.update_layout(
xaxis=dict(title_text="(-) «──────────── Risk ────────────» (+)", showgrid=False, showticklabels=False, rangemode='tozero', mirror=True, linewidth=2),
yaxis=dict(title_text="(-) «──────── Return ────────» (+)", showgrid=False, showticklabels=False, rangemode='tozero', mirror=True, linewidth=2),
)
fig.update_layout(width=1000, height=500)
return fig
def lp_insights(df_lp: pd.DataFrame)-> go.Figure:
fig = go.Figure()
fig = make_subplots(specs=[[{"secondary_y": True}]])
fig.add_trace(
go.Bar(
x=df_lp["date"],
y=df_lp["tvl"],
name="TVL",
),
secondary_y=True,
)
fig.update_traces(
marker_color="rgb(252,149,79)",
marker_line_color="rgb(20,76,157)",
marker_line_width=0.5,
opacity=0.4,
)
fig.add_trace(
go.Scatter(
x=df_lp["date"],
y=df_lp["base"],
name="Base APY",
),
secondary_y=False,
)
fig.add_trace(
go.Scatter(
x=df_lp["date"],
y=df_lp["reward"],
name="Reward Token",
),
secondary_y=False,
)
fig.add_trace(
go.Scatter(
x=df_lp["date"],
y=df_lp["apy"],
name="Total APY",
),
secondary_y=False,
)
fig.update_layout(
legend=dict(
orientation="h",
y=-0.1,
x=0.25,
)
)
fig.update_yaxes(showgrid=False, tickformat='0%',title_text="Base APY & Reward Token", secondary_y=False)
fig.update_yaxes(showgrid=False, title_text="TVL", secondary_y=True)
fig.update_layout(width=1000, height=500, plot_bgcolor="rgb(255,255,255)")
return fig
def reward_token_insights(reward_token_timeseries)-> go.Figure:
fig = go.Figure()
fig = make_subplots(specs=[[{"secondary_y": True}]])
fig.add_trace(
go.Bar(
x=reward_token_timeseries['date'],
y=reward_token_timeseries['market_cap'],
name="Market Cap",
),
secondary_y=True,
)
fig.update_traces(
marker_color="rgb(252,149,79)",
marker_line_color="rgb(20,76,157)",
marker_line_width=0.5,
opacity=0.4,
)
fig.add_trace(
go.Scatter(
x=reward_token_timeseries['date'],
y=reward_token_timeseries['price'],
name="Price",
),
secondary_y=False,
)
fig.update_layout(
legend=dict(
orientation="h",
y=-0.1,
x=0.25,
)
)
fig.update_yaxes(showgrid=False, title_text="Price", secondary_y=False)
fig.update_yaxes(showgrid=False, title_text="Market Cap", secondary_y=True)
fig.update_layout(width=1000, height=500, plot_bgcolor="rgb(255,255,255)")
return fig