Drawing a huge graph with networkX and matplotlib
30,108
Solution 1
You have two easy options:
Up the DPI
plt.savefig("graph.png", dpi=1000)
(larger image file size)
Save as a PDF
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.
Solution 2
While not in GTK, you might want to check out NetworkX Viewer.
Author by
Nihar Sarangi
Updated on February 21, 2020Comments
-
Nihar Sarangi over 4 years
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)
-
Hooked about 12 years@NiharSarangi I feel like the question "save a magnified version for proper visualisation later" has been answered. If the image is messy and you want to customize
networkx
that might be fodder for a different question. Try turning off the labelswith_labels=True
->with_labels=False
in your draw command to clean it up.