How to add dot's graph attribute into final dot output

Viewed 2248

I create representation of graph with NetworkX library in my python project. Making directed graph I need to add an attribute to our graph output: rankdir=LR

So I'm writing the code:

import networkx as nx
graph = nx.DiGraph(rankdir="LR")
#adding deps based on our database data
add_deps(graph)
dot_file_path = "some/path/to/dots.gv"

nx.write_dot(graph, dot_file_path)

So, last string generates dot file with next content:

strict digraph  {
    "Writing letters"    [URL="/admin/materials/theme/213/",
        shape=box,
        target=blank];
    "Finishing the Business English course"  [URL="/admin/materials/theme/221/",
        color=red,
        shape=box,
        style=filled,
        target=blank];
    "Writing letters" -> "Finishing the Business English course";
    ... 
}

While I expect the code where attribute "rankdir=LR" will be attached to the graph output:

strict digraph  {
    rankdir=LR;
    "Writing letters"    [URL="/admin/materials/theme/213/",
        shape=box,
        target=blank];
    "Finishing the Business English course"  [URL="/admin/materials/theme/221/",
        color=red,
        shape=box,
        style=filled,
        target=blank];
    "Writing letters" -> "Finishing the Business English course";
    ... 
}

But this doesn't happen, seems that write_dot() method doesn't put graph atrributes. Could anyone help me with advice of the correct way of adding graph attributes through networkx?

2 Answers
Related