Graphviz and Jupyter NotebookΒΆ

From version 6.0.0, binarytree can integrate with Graphviz to render trees in image viewers, browsers and Jupyter notebooks using the python-graphviz library.

In order to use this feature, you must first install the Graphviz software in your OS and ensure its executables are on your PATH system variable (usually done automatically during installation):

# Ubuntu and Debian
$ sudo apt install graphviz

# Fedora and CentOS
$ sudo yum install graphviz

# Windows using choco (or winget)
$ choco install graphviz

Use binarytree.Node.graphviz() to generate graphviz.Digraph objects:

from binarytree import tree

t = tree()

# Generate a graphviz.Digraph object
# Arguments to this method are passed into Digraph.__init__
graph = t.graphviz()

# Get DOT (graph description language) body
graph.body

# Render the binary tree
graph.render()

With Graphviz you can also visualize binary trees in Jupyter notebooks:

Jupyter Notebook GIF