-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdistribution_plot.py
119 lines (103 loc) · 3.18 KB
/
distribution_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
import os
import plotly.graph_objects as go
import pandas as pd
GRID_COLOR: str = '#B0BEC5'
BLUE: str = '#2471a3'
def update_layout(fig: go.Figure) -> None:
fig.update_layout(
xaxis={
'tick0': 0,
'dtick': 20,
'ticks': 'outside',
'ticklen': 5,
'tickwidth': 2,
'tickangle': 45,
'tickfont': {'size': 14},
'showline': True,
'linewidth': 2,
'linecolor': 'black',
},
yaxis={
'showgrid': True,
'gridwidth': 0.5,
'gridcolor': GRID_COLOR,
'ticks': 'outside',
'ticklen': 5,
'tickwidth': 2,
'tickfont': {'size': 14},
'showline': True,
'linewidth': 2,
'linecolor': 'black',
'tick0': 0,
'dtick': 1,
},
plot_bgcolor="white",
legend={'orientation': 'h', 'x': 0, 'y': 1.2},
)
if __name__ == '__main__':
filename: str = os.path.join('datawarehouse', 'census.csv')
df: pd.DataFrame = pd.read_csv(filename, header=0)
# users
fig = go.Figure(data=[go.Histogram(
x=df['nUsers'].tolist(),
xbins={'size': 10.0, 'start': 1.0},
marker_color=BLUE,
name='DAOs in bins of 10',
)])
fig.add_trace(go.Scatter(
x=[0, 0],
y=[0, len(df[df['nUsers'] == 0])],
line=dict(color='firebrick', width=4),
name='DAOs with 0 users'
))
update_layout(fig=fig)
fig.update_layout(xaxis_title_text='Number of users', yaxis_title_text='Number of DAOs')
fig.show()
# proposals
fig = go.Figure(data=[go.Histogram(
x=df['nProposals'].tolist(),
xbins={'size': 10.0, 'start': 1.0},
marker_color=BLUE,
name='DAOs in bins of 10',
)])
fig.add_trace(go.Scatter(
x=[0, 0],
y=[0, len(df[df['nProposals'] == 0])],
line=dict(color='firebrick', width=4),
name='DAOs with 0 proposals'
))
update_layout(fig=fig)
fig.update_layout(xaxis_title_text='Number of proposals', yaxis_title_text='Number of DAOs')
fig.show()
# votes
fig = go.Figure(data=[go.Histogram(
x=df['nVotes'].tolist(),
xbins={'size': 10.0, 'start': 1.0},
marker_color=BLUE,
name='DAOs in bins of 10',
)])
fig.add_trace(go.Scatter(
x=[0, 0],
y=[0, len(df[df['nVotes'] == 0])],
line=dict(color='firebrick', width=4),
name='DAOs with 0 votes'
))
update_layout(fig=fig)
fig.update_layout(xaxis_title_text='Number of votes', yaxis_title_text='Number of DAOs')
fig.show()
# stakes
fig = go.Figure(data=[go.Histogram(
x=df['nStakes'].tolist(),
xbins={'size': 10.0, 'start': 1.0},
marker_color=BLUE,
name='DAOs in bins of 10',
)])
fig.add_trace(go.Scatter(
x=[0, 0],
y=[0, len(df[df['nStakes'] == 0])],
line=dict(color='firebrick', width=4),
name='DAOs with 0 stakes'
))
update_layout(fig=fig)
fig.update_layout(xaxis_title_text='Number of stakes', yaxis_title_text='Number of DAOs')
fig.show()