# Best way to plot graph

Hello!

Could you pleas advise me the best way to plot graph with cycles and make it looks like tree? Here is the sample picture of result I'd like to have:

Plot on this pictures have 'layers', is there any chance to get something like this in Sage? I tried this:

t = DiGraph()

t.plot()


but the result is far from desired.

Thanks.

edit retag close merge delete

Sort by ยป oldest newest most voted

You can use:

t.plot(pos=t.layout_acyclic())


If you get arrows pointing up it means you don't have the dot2tex package installed (you can check this with sage.graphs.dot2tex_utils.have_dot2tex()), and sage does the positioning itself (by calling t.layout_acyclic_dummy()). Just run install_package('dot2tex-2.8.7-2') (perhaps the version number will change one day, type optional_packages() to see all packages available).

You can also manually flip sage's positioning:

l = t.layout_acyclic_dummy()
t.plot(pos=dict([[v,[l[v][0],-l[v][1]]] for v in t.vertices()]))


or rotate it like in the image in the question:

l = t.layout_acyclic_dummy()
t.plot(pos=dict([[v,[l[v][1],l[v][0]]] for v in t.vertices()]))

more

This method works great, thank you! But is it possible somehow change orientation of the result tree-like graph? Something like tree_orientation='down' effect for actual tree.

( 2011-07-15 01:32:00 +0200 )edit

Ok, I checked what happens and updated my answer.

( 2011-07-15 05:52:15 +0200 )edit

Thank you! This solution works perfectly correct.

( 2011-07-15 14:16:19 +0200 )edit

( 2011-07-15 18:57:46 +0200 )edit