Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Placing nodes vertically in Graphviz using pydot

I am using Graphviz in Python via pydot. The diagram I am making has many clusters of directed graphs. pydot is putting them next to each other horizontally resulting in an image that is very wide. How can I tell it to output images of a maximum width so that I can scroll vertically instead?

like image 455
hekevintran Avatar asked Feb 07 '10 01:02

hekevintran


2 Answers

I'm not sure if you're able to do this with your data, but if you change the order that the nodes are inserted into the graph it can really affect the generated graph. If you don't want to supply any ordering information to Graphviz and want Graphviz to attempt solving optimal placement of nodes to minimize contention, use Graphviz's neato instead. It uses a spring model to figure out where nodes should be placed.

It looks like you should be able to use neato inside pydot like:

my_graph.write('my_graph.png', prog='neato', format='png')

See pydot's documenation here.

like image 152
Ross Rogers Avatar answered Sep 19 '22 09:09

Ross Rogers


Initialize your graph like this:

graph = pydot.Dot(graph_type='digraph', rankdir='LR')

This will set the graph direction from left to right. In general, use the graphviz documentation to find the right attribute in order to achieve what you want.

like image 28
Michel Müller Avatar answered Sep 19 '22 09:09

Michel Müller