I'm trying to find the lowest ranking node because I want to always put something at the very bottom of the graph. Is there a way to do something like G.lowest_rank() and it would return the string of the node?
If not, how do I achieve this?
I'm trying to find the lowest ranking node because I want to always put something at the very bottom of the graph. Is there a way to do something like G.lowest_rank() and it would return the string of the node?
If not, how do I achieve this?
Actually, there are special values for subraph rank attribute called max and sink which allow you to put a node in the lowest rank.
rank=max then the node will appear on the already existing lowest rank.rank=sink then the node have its own rank which is below the lowest rank of the graph, example:digraph {
a -> b -> c
{
rank=max
bottom1 [label="rank=max"]
}
}
digraph {
a -> b -> c
{
rank=sink
bottom1 [label="rank=sink"]
}
}
I am not too familiar with PyGraphviz, but to achieve the same result there you can do something like this:
G = pgv.AGraph(directed=True)
G.add_node('a')
G.add_node('b')
G.add_node('c')
G.add_node('bottom1', label="rank=sink")
G.add_edge('a','b')
G.add_edge('b','c')
G.add_subgraph(['bottom1'], name='s1', rank='sink')