Reputation: 47
I'm working on reconstructing the article: "Social network analysis of manga: similarities to real-world social networks and trends over decades". This is the link to the article: text. I am having trouble working and coding relating to bipartite graph. Although they said that the files can be read using read_weighted_edgelist
in networkx
, i can not plot the same graph with thickness for edges.
I hope to get some advice and help for the two below problems.
This is the code i have done:
import networkx as nx
import matplotlib.pyplot as plt
G = nx.Graph()
G = nx.read_weighted_edgelist('D:\TS2VG\Manga_network_data\Static\Static_One_Piece.edgelist')
pos = nx.random_layout(G)
nx.draw(G, pos, with_labels = True)
plt.show()
Upvotes: 0
Views: 147
Reputation: 37847
Yes, it's counter-intuitive but to make the edges' thickness proportional to their weights, you need to do it manually when calling draw_network_egdes
(even though, initially, you're building the graph from a weighted edgelist.)
Also, from what I can understand in the image you shared, this applies only to a specific node :
import networkx as nx
import matplotlib.pyplot as plt
# https://github.com/KS-92/Manga/blob/main/Manga_network_data.zip
G = nx.read_weighted_edgelist("Static_One_Piece.edgelist")
pos = nx.random_layout(G, seed=2)
NODE = "19" # assuming this refers to Monkey D.Luffy
nx.draw_networkx_nodes(G, pos, node_size=100, node_color="#7197cf")
for s, t, w in G.edges(data="weight"):
nx.draw_networkx_edges(G, pos, edgelist=[[s, t, w]],
width=w//5 if s == NODE else 0.5)
plt.annotate("", xy=pos[NODE], xytext=(pos[NODE][0]-0.1, pos[NODE][1]+0.2),
arrowprops=dict(facecolor="orange", edgecolor="orange",
arrowstyle="fancy", linewidth=2))
plt.axis("off")
plt.show()
Preview :
Upvotes: 0