keeping nodes' positions fixed

Hello,

I created some graphs using the following command (one graph per year):
neato -Gsplines -Tpdf filename1.dot -o filename1.pdf
neato -Gsplines -Tpdf filename2.dot -o filename2.pdf
...

In this graph, some nodes may change properties each year (for example, see the attached combined file which show output for ten years).

As you can see, the nodes' positions changed from one year to the next (I understand this is how graphviz/neato layout automatically place the nodes).

However, I'd like to keep the nodes' positions fixed, so that the time-varying graphs make more sense (ideally, I'd like to see only new edges created or some old edges removed).

Perhaps the -n option with neato may work, but I do not know the exact (initial) positions for my nodes (to specify as "pos" attribute in the dot files).

Is there a way to achieve this?

Thanks in advance!

This can be easily done. Take

This can be easily done. Take a graph containing all of the nodes and the union of all edges that appear over the years.  Set an attribute on each edge describing the years it should be visible. Then make an initial layout for this full graph:

   neato -Gsplines fullgraph.gv > fullgraph_pos.gv

The output will be the layout with dot format containing all of the position information. Then, for each year, filter out the edges that don't belong to that year and pipe the output to neato -n2 -Tpdf.

The typical tool for filtering in graphviz is gvpr. Assume, for simplicity, that an edge only appears in a range of years, so that in the graph, each edge has attributes first_year and last_year. You could use a gvpr script in a file strip.g:

BEGIN {
  int year = (int)ARGV[0];
}
E [(year < (int)first_year) || (int)last_year < year] {delete($G,$)}

and run gvpr -c -a1940 fullgraph_pos.gv | neato -n2 -Tpdf > graph1940.pdf

to get the graph for 1940. Of course, you can extend range matching, error checking, etc. to fit your needs.

 

 

Recent comments