Graphviz.Source not rendering in Jupyter Notebook

graphvizipythonjupyter-notebookscikit-learn

After exporting a .dot file using scikit-learn's handy export_graphviz function.

I am trying to render the dot file using Graphviz into a cell in my Jupyter Notebook:

import graphviz
from IPython.display import display

with open("tree_1.dot") as f:
    dot_graph = f.read()
display(graphviz.Source(dot_graph))

However the out[ ] is just an empty cell.

I am using graphviz 0.5 (pip then conda installed), iPython 5.1, and Python 3.5
The dot file looks correct here are the first characters:

digraph Tree {\nnode [shape=box, style="filled", color=

iPython display seems to work for other objects including Matplotlib plots and Pandas dataframes.

I should note the example on Graphviz' site also doesn't work.

Best Answer

It's possible that since you posted this, changes were made so you might want to update your libraries if that's possible.

The versions of relevance here I used are:

Python 2.7.10

IPython 5.1.0

graphviz 0.7.1

If you have a well formed .dot file, you can display it to the jupyter out[.] cell by the following:

import graphviz

with open("tree_1.dot") as f:
    dot_graph = f.read()

# remove the display(...)

graphviz.Source(dot_graph)