Skip to content

Commit

Permalink
nxdrawing.py added
Browse files Browse the repository at this point in the history
  • Loading branch information
chapmanbe committed Nov 22, 2017
1 parent efe9533 commit 88b820d
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions modules/m16_graphs/InClass/nxdrawing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import networkx as nx

from IPython.display import Image

def draw_dot(graph, file):
"""
Writes a graph to png using pydot and returns that file
as an IPython Image object
IPython.display.Image
Arguments:
graph: a NetworkX graph
file: a file name to save png file to
"""
if not file.endswith(".png"):
file = file+".png"
ag = nx.nx_pydot.to_pydot(graph)
ag.write_png(file)
return Image(filename=file)

0 comments on commit 88b820d

Please sign in to comment.