Skip to content

Instantly share code, notes, and snippets.

@sllynn
Created August 18, 2020 17:57
Show Gist options
  • Save sllynn/298d6714450823a223ebab89649b3dae to your computer and use it in GitHub Desktop.
Save sllynn/298d6714450823a223ebab89649b3dae to your computer and use it in GitHub Desktop.
Display a graphviz Graph or Digraph in a notebook
def plot_graphviz(graph):
from tempfile import NamedTemporaryFile
from base64 import b64encode
with NamedTemporaryFile(suffix=".png") as fh:
graph.plot(to_file=fh.name)
img = b64encode(fh.read()).decode("UTF-8")
displayHTML(f"<img src='data:image/png;base64,{img}'>")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment