Last active
April 9, 2021 00:17
-
-
Save EDDxample/ab965a14934bc30c283689831f4ad5f6 to your computer and use it in GitHub Desktop.
Renders graph based on multiple twitterfamily outputs
This file contains hidden or 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
from collections import defaultdict | |
import networkx as nx, matplotlib.pyplot as plt | |
class Node: | |
def __init__(self): | |
self.partners = defaultdict(int) | |
self.children = defaultdict(int) | |
def __repr__(self): | |
return f'\npartners: {dict(self.partners)}\nchildren: {dict(self.children)}\n' | |
def main(): | |
nodes = defaultdict(Node) | |
# build nodes | |
with open('twitterfamily.txt', 'r') as f: | |
for line in f.readlines()[1:]: # skip headers | |
p1, p2, user, partner, c1, c2 = line.strip().split(',') | |
nodes[user].partners[partner] += 1 | |
nodes[user].children[c1] += 1 | |
nodes[user].children[c2] += 1 | |
nodes[partner].partners[user] += 1 | |
nodes[partner].children[c1] += 1 | |
nodes[partner].children[c2] += 1 | |
nodes[p1].partners[p2] += 1 | |
nodes[p1].children[user] += 1 | |
nodes[p2].partners[p1] += 1 | |
nodes[p2].children[user] += 1 | |
g = nx.Graph() | |
for user in nodes: | |
node = nodes[user] | |
for partner in node.partners: | |
g.add_edge(user, partner, color='red', weight=node.partners[partner]) | |
for child in node.children: | |
g.add_edge(user, child, color='orange', weight=node.children[child]) | |
colors = nx.get_edge_attributes(g,'color').values() | |
weights = nx.get_edge_attributes(g,'weight').values() | |
nx.draw(g, edge_color=colors, width=list(weights), with_labels=True, node_color='lightgreen') | |
plt.show() | |
if __name__ == '__main__': main() |
This file contains hidden or 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
parent1,parent2,me,partner,child1,child2 | |
guisigo05,Leondoor2,Juniii011,killis_24,Jorvp_,buiz_el | |
TheGoldenSmurf,tet_50,Jorvp_,Juniii011,EDDxample,Sanyeki54 | |
marcoslaliena_,4nDu_,elhuevitou,daniel297978,TVTvirusOW,Juniii011 | |
Panda234uwu,MisterJagger_,Leondoor2,Juniii011,Jorvp_,basti_s3 | |
Juniii011,CuentaMister,DanieloideXD_YT,UrsSalvador,ElRichMC,AiranHemzi | |
EDDxample,Noval33t,tet_50,Juniii011,Jorvp_,ScienceVideos_ | |
TVTvirusOW,elonmusk,OSO55093180,Juniii011,carlosdp2002f_,ElgamerJohny | |
killis_24,Xtrecx,guisigo05,Juniii011,Jorvp_,HumansNoContext | |
Juniii011,Leondoor2,Feeliseee,SoyElDeCarlos,Arpex_,killis_24 | |
seraglo95,doraemongamer48,Tas_belial,EliArmasZero,Juniii011,EDDxample | |
ArtRmnFox,AlephSmp,Kelecraft1,Juniii011,matulul,Drikon_ | |
ElgamerJohny,zGamerX_18,GamerNalias,Juniii011,Leondoor2,MinecraftMeme16 | |
irati_abad28,Juniii011,44Hodei,Kelecraft1,PepinoConFlow,44Hodei | |
TVTvirusOW,DrWho1984,Alphity_576,_Aosiika,Juniii011,Smol_and_Sassy | |
Kelecraft1,AzNaKKKK1,matulul,Juniii011,makihourly,Drikon_ | |
mrcarlosnoob,Ivan2lc,luiggi_2001,luciia654,Juniii011,xhelenals | |
ElgamerJohny,IamLokillo,carlosdp2002f_,TVTvirusOW,Juniii011,OSO55093180 | |
doraemongamer48,Tas_belial,seraglo95,PetsArts,Ekusutashi27,Juniii011 | |
Merylol22,guisigo05,killis_24,Juniii011,Junni011,MandyMelody00 | |
guisigo05,ElumaChan,M4k3rM4rc0s,Juniii011,xarg3579,zGamerX_18 | |
M4k3rM4rc0s,Herreros__,ElumaChan,Juniii011,AlephSmp,ThorJaimeMc | |
Junni011,EDDxample,JairoAn55038432,Juniii011,PoisonDager,ZerphyArtWorks |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment