I have an interactome file composed of more than 600,000 entries. I am trying to map it using NetworkX and Matplotlib.
This is the code I am running:
import networkx as nx
import matplotlib.pyplot as plt
from networkx.drawing.nx_agraph import graphviz_layout
ppi_file = r"F:\Python Project\PathLinker_2018_human-ppi-weighted-cap0_75.txt"
G = nx.DiGraph()
with open(ppi_file, "r") as file:
next(file)
for line in file:
tail, head, edge_weight, edge_type = line.strip().split("\t")
G.add_edge(tail, head, edge_weight=float(edge_weight), edge_type=edge_type)
pos = graphviz_layout(G)
plt.figure(figsize=(150, 150)) # Adjust the figure size as needed
nx.draw_networkx_nodes(G, pos,node_size=3000)
nx.draw_networkx_labels(G, pos)
nx.draw_networkx_edges(G, pos, arrows=False)
# Save the plot as an image file
plt.savefig("ppi_network.png", dpi=300) # Adjust the dpi (dots per inch) as needed
plt.show()
The output is this image:
How can I make the network clearer and not stacked on top of one another as shown in the image?
I tried increasing the dimensions of the figure multiple times, each time it's slightly better, but it everytime it's more computationally expensive. I also used the graphviz layout as many others suggested, but the output is still crammed together.
How can I fix this?