I am drawing a graph with around 5K nodes in it using networkX and matplotlib. The GTK window by matplotlib has tools to zoom and visualise the graph. Is there any way, I can save a magnified version for proper visualisation later?
import matplotlib.pyplot as plt import networkx as nx pos=nx.spring_layout(G) #G is my graph nx.draw(G,pos,node_color='#A0CBE2',edge_color='#BB0000',width=2,edge_cmap=plt.cm.Blues,with_labels=True) #plt.show() plt.savefig("graph.png", dpi=500, facecolor='w', edgecolor='w',orientation='portrait', papertype=None, format=None,transparent=False, bbox_inches=None, pad_inches=0.1)
NX is certainly capable of handling graphs that large, however, performance will largely be a function of your hardware setup. Aric will likely give a better answer, but NX loads graphs into memory at once, so in the ranges your are describing you will need a substantial amount of free memory for it to work.
Option 1: NetworkX NetworkX has its own drawing module which provides multiple options for plotting. Below we can find the visualization for some of the draw modules in the package. Using any of them is fairly easy, as all you need to do is call the module and pass the G graph variable and the package does the rest.
NetworkX is pure Python, well documented and handles changes to the network gracefully. iGraph is more performant in terms of speed and ram usage but less flexible for dynamic networks. iGraph is a C library with very smart indexing and storage approaches so you can load pretty large graphs in ram.
NetworkX provides a standardized way for data scientists and other users of graph mathematics to collaborate, build, design, analyze, and share graph network models. As free software that's notable for its scalability and portability, NetworkX has been widely adopted by Python enthusiasts.
You have two easy options:
plt.savefig("graph.png", dpi=1000)
(larger image file size)
plt.savefig("graph.pdf")
This is the best option, as the final graph is not rasterized. In theory, you should be able to zoom in indefinitely.
While not in GTK, you might want to check out NetworkX Viewer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With