Skip to content

Instantly share code, notes, and snippets.

@clayadavis
Created May 31, 2013 16:58
Show Gist options
  • Save clayadavis/5686333 to your computer and use it in GitHub Desktop.
Save clayadavis/5686333 to your computer and use it in GitHub Desktop.
How to draw network layouts to files. Run this in a Python shell.
import matplotlib
#This has to go before importing pyplot
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import networkx as nx
# Make your graph
G = nx.dodecahedral_graph()
# There are many configuration options available for nx.draw
# http://networkx.github.io/documentation/latest/reference/generated/networkx.drawing.nx_pylab.draw_networkx.html#networkx.drawing.nx_pylab.draw_networkx
nx.draw(G)
plt.savefig('graph_image.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment