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
有帮助吗?

解决方案

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top