Plotting trees using TikzPictures.jl and the latex package tikz-qtree.
Install the latest version of this package by:
(v0.7) pkg> add https://github.com/dharasim/TikzQTrees.jl#master
TikzQTrees is build on top of TikzPictures.jl. If you can install TikzPictures, you should also be able to use TikzQTrees.
The package implements a wrapper type TikzQTree
of tree data types which implement the functions
value(tree)
that returns the value of the root of the tree, andchildren(tree)
that returns an iterator over the children of the root of the tree.
It also provides SimpleTree
, an example of a type that can be wrapped into TikzQTree
:
mutable struct SimpleTree{T}
value :: T
children :: Vector{SimpleTree{T}}
end
TikzQTrees are converted into TikzPictures to show them in the Juno plot pane and IJulia notebooks. In the REPL, the tex code of the tikz-qtree is printed.
julia> using TikzQTrees, TikzPictures
julia> tree = SimpleTree("root", [SimpleTree("left"), SimpleTree("right")]);
julia> TikzQTree(tree)
[.root left right ]
julia> save(SVG("test_tree"), TikzPicture(TikzQTree(tree)))
The saved plot is:
This package additionally provides the macro @qtree
for pretty printing of Julia's syntax trees:
julia> qt = @qtree a * (b+c) == a*b + a*c
[.{==} [.{*} {a} [.{+} {b} {c} ] ] [.{+} [.{*} {a} {b} ] [.{*} {a} {c} ] ] ]
julia> save(SVG("distributivity"), TikzPicture(qt))
TreeView.jl is a related package that implements a macro @tree
which is build on top of TikzGraphs.jl.