Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

horizontal tree with graphviz_layout

in python, with networkx. I can plot a vertical tree with :

   g=nx.balanced_tree(2,4)
   pos = nx.graphviz_layout(g, prog='dot')
   nx.draw(g,pos,labels=b_all, node_size=500)
   plt.show()

similar to

   [root]
     |
  |      |
 node   node

how I can plot a horizontal tree ?

        -- node
[root] - 
        -- node
like image 504
JuanPablo Avatar asked Jun 20 '13 02:06

JuanPablo


1 Answers

Pass -Grankdir=LR option to dot:

pos = nx.graphviz_layout(G, prog='dot', args="-Grankdir=LR")

https://graphviz.org/doc/info/command.html

https://graphviz.org/doc/info/attrs.html#d:rankdir

like image 76
falsetru Avatar answered Nov 01 '22 09:11

falsetru