# How to lay out binary tree / hierarchicy?

**URL:** https://forum.graphviz.org/t/how-to-lay-out-binary-tree-hierarchicy/610
**Category:** Help
**Created:** [April 14, 2021, 2:57am UTC](https://forum.graphviz.org/t/how-to-lay-out-binary-tree-hierarchicy/610 "2021-04-14T02:57:58Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![athompso](https://avatars.discourse-cdn.com/v4/letter/a/aca169/32.png) [@athompso](https://forum.graphviz.org/u/athompso)
#### Post date: [April 14, 2021, 2:57am UTC](https://forum.graphviz.org/t/how-to-lay-out-binary-tree-hierarchicy/610/1 "2021-04-14T02:57:58Z")

</div>

I’m trying to visually represent a large-ish binary tree.  
Dot is doing a reasonable job _except_ that it won’t keep the pieces of the tree separated - it shoves deeper bits of the tree over underneath shallower parts of the tree.  
Neato with mode=hier comes a bit closer, but the output is extremely messy, with everything on a rank overlapping each other, and the children behaving as though I’ve set ranksep to -50% (which I haven’t done, and I don’t think is even possible).

Before I waste a ton of time trying to tweak dot or neato, am I on the right path?  
If it were easier to use and programatically feed, and I didn’t mind manually editing or tweaking every file, I might consider using yEd/yFiles for this as its Hierarchical layout mode is almost exactly what I want, but Graphviz is a **much** better fit for this project architecturally so I really want to make it work instead.

BTW, the graph itself is being output from Python’s NetworkX library using pydot, although it’s simple enough at this stage that I don’t think that matters.

Any help appreciated!

---

<div class="post-metadata">

### Author: ![mark](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/mark/32/84_2.png) [@mark](https://forum.graphviz.org/u/mark)
#### Post date: [April 14, 2021, 3:30am UTC](https://forum.graphviz.org/t/how-to-lay-out-binary-tree-hierarchicy/610/2 "2021-04-14T03:30:36Z")

</div>

Attaching your input and output would help if that’s possible? Or an anonymised version

---

<div class="post-metadata">

### Author: ![steveroush](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@steveroush](https://forum.graphviz.org/u/steveroush)
#### Post date: [April 14, 2021, 3:47am UTC](https://forum.graphviz.org/t/how-to-lay-out-binary-tree-hierarchicy/610/3 "2021-04-14T03:47:16Z")

</div>

Without either input or output, it’s hard to say much. If you can produce **canon** or **dot** output type and share it, that would help (recreating your input).

- One off-the-wall idea: try **twopi** and **circo**.
- A half-baked off-the-wall idea: to stop **dot** from being to efficient with space, embed each parent node and its children in a cluster - and include subsequent clusters within that cluster.  
I.e. nested clusters out the wazoo.  
I’ve never tried this, but have some hope for the idea.

---

<div class="post-metadata">

### Author: ![scnorth](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/scnorth/32/89_2.png) [@scnorth](https://forum.graphviz.org/u/scnorth)
#### Post date: [April 14, 2021, 5:49pm UTC](https://forum.graphviz.org/t/how-to-lay-out-binary-tree-hierarchicy/610/4 "2021-04-14T17:49:01Z")

</div>

Greetings. We don’t have a classic tree layout algorithm in graphviz. It would be a nice student project, really, or if the tree is generated by another program you could have it do the layout as well by setting the node positions. Basically you’re just using graphviz as a graphics driver.
