-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
19 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |