Ivan Kudryakov
commited on
Commit
·
0f136ae
1
Parent(s):
1e1e13f
commit 1
Browse files
app.py
CHANGED
@@ -97,4 +97,85 @@ nx.draw_networkx_nodes(G, pos, node_size=50)
|
|
97 |
nx.draw_networkx_edges(G, pos, edge_color='b')
|
98 |
# plt.show()
|
99 |
|
100 |
-
st.pyplot(plt)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
nx.draw_networkx_edges(G, pos, edge_color='b')
|
98 |
# plt.show()
|
99 |
|
100 |
+
st.pyplot(plt)
|
101 |
+
|
102 |
+
|
103 |
+
|
104 |
+
edge_x = []
|
105 |
+
edge_y = []
|
106 |
+
for edge in G.edges():
|
107 |
+
x0, y0 = pos.get(edge[0]) # G.nodes[edge[0]]['pos']
|
108 |
+
x1, y1 = pos.get(edge[1]) # G.nodes[edge[1]]['pos']
|
109 |
+
edge_x.append(x0)
|
110 |
+
edge_x.append(x1)
|
111 |
+
edge_x.append(None)
|
112 |
+
edge_y.append(y0)
|
113 |
+
edge_y.append(y1)
|
114 |
+
edge_y.append(None)
|
115 |
+
|
116 |
+
edge_trace = go.Scatter(
|
117 |
+
x=edge_x, y=edge_y,
|
118 |
+
line=dict(width=0.5, color='#888'),
|
119 |
+
hoverinfo='none',
|
120 |
+
mode='lines')
|
121 |
+
|
122 |
+
node_x = []
|
123 |
+
node_y = []
|
124 |
+
for node in G.nodes():
|
125 |
+
# print(node)
|
126 |
+
x, y = pos.get(node) # G.nodes[node]['pos']
|
127 |
+
node_x.append(x)
|
128 |
+
node_y.append(y)
|
129 |
+
|
130 |
+
node_trace = go.Scatter(
|
131 |
+
x=node_x, y=node_y,
|
132 |
+
mode='markers',
|
133 |
+
hoverinfo='text',
|
134 |
+
marker=dict(
|
135 |
+
showscale=True,
|
136 |
+
# colorscale options
|
137 |
+
# 'Greys' | 'YlGnBu' | 'Greens' | 'YlOrRd' | 'Bluered' | 'RdBu' |
|
138 |
+
# 'Reds' | 'Blues' | 'Picnic' | 'Rainbow' | 'Portland' | 'Jet' |
|
139 |
+
# 'Hot' | 'Blackbody' | 'Earth' | 'Electric' | 'Viridis' |
|
140 |
+
colorscale='YlGnBu',
|
141 |
+
reversescale=True,
|
142 |
+
color=[],
|
143 |
+
size=10,
|
144 |
+
colorbar=dict(
|
145 |
+
thickness=15,
|
146 |
+
title='Node Edges',
|
147 |
+
xanchor='left',
|
148 |
+
titleside='right'
|
149 |
+
),
|
150 |
+
line_width=2))
|
151 |
+
|
152 |
+
node_adjacencies = []
|
153 |
+
node_text = []
|
154 |
+
#print(MyFriendsDict)
|
155 |
+
# print(G_nodes_list[1])
|
156 |
+
# print(MyFriendsDict[G_nodes_list[1]]['first_name'])
|
157 |
+
for node, adjacencies in enumerate(G.adjacency()):
|
158 |
+
node_adjacencies.append(len(adjacencies[1]))
|
159 |
+
node_text.append(MyFriendsDict[G_nodes_list[node]]['first_name'] + ' ' + MyFriendsDict[G_nodes_list[node]]['last_name'] + ' ' + str(len(adjacencies[1])) + ' edges')
|
160 |
+
# print(node)
|
161 |
+
|
162 |
+
node_trace.marker.color = node_adjacencies
|
163 |
+
node_trace.text = node_text
|
164 |
+
|
165 |
+
fig = go.Figure(data=[edge_trace, node_trace],
|
166 |
+
layout=go.Layout(
|
167 |
+
title='<br>Social graph to ' + myFirstAndLastName.json()['response'][0]['first_name'] + ' ' + myFirstAndLastName.json()['response'][0]['last_name'],
|
168 |
+
titlefont_size=16,
|
169 |
+
showlegend=False,
|
170 |
+
hovermode='closest',
|
171 |
+
margin=dict(b=20, l=5, r=5, t=40),
|
172 |
+
annotations=[dict(
|
173 |
+
text="Python code: <a href='https://github.com/Akuva2001/SocialGraph'> https://github.com/Akuva2001/SocialGraph</a>",
|
174 |
+
showarrow=False,
|
175 |
+
xref="paper", yref="paper",
|
176 |
+
x=0.005, y=-0.005)],
|
177 |
+
xaxis=dict(showgrid=False, zeroline=False, showticklabels=False),
|
178 |
+
yaxis=dict(showgrid=False, zeroline=False, showticklabels=False))
|
179 |
+
)
|
180 |
+
st.plotly_chart(fig)
|
181 |
+
# fig.show()
|