Last active
July 21, 2018 12:25
-
-
Save traderbagel/4080930ad3b70c46abc8813df14f7932 to your computer and use it in GitHub Desktop.
visualize txs network
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
from matplotlib.pyplot import figure | |
figure(num=None, figsize=(20, 16), dpi=80, facecolor='w', edgecolor='k') | |
import networkx as nx | |
import math | |
pos = nx.spring_layout(G) | |
# Draw Nodes | |
# recived/ sent | |
receive_ratio = {n: (sum([e[2] for e in G.edges().data('weight') if e[1] == n]) / | |
(sum([e[2] for e in G.edges().data('weight') if e[0] == n]) or 1)) | |
for n in G} | |
max_ra = max([x[1] for x in receive_amount.items()]) + 1 | |
values = [receive_amount[n]/2 | |
if receive_amount[n] < 1 else | |
((receive_amount[n]+1)/max_ra/Decimal(2)+Decimal(0.5)) | |
for n in G.nodes()] | |
nx.draw_networkx_nodes(G, pos, cmap=plt.get_cmap('cool'), node_color = values, node_size = 200, opacity=0.1) | |
# Draw Edges | |
red_edges = [(e[0], e[1]) for e in G.edges.data('weight') if e[2] >= Decimal(400)] | |
edge_colours = ['black' if not edge in red_edges else 'red' for edge in G.edges()] | |
black_edges = [edge for edge in G.edges() if edge not in red_edges] | |
nx.draw_networkx_edges(G, pos, edgelist=red_edges, edge_color='r', arrows=True) | |
nx.draw_networkx_edges(G, pos, edgelist=black_edges, arrows=False) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment