Ferda-Ozdemir-Sonmez
Ferda-Ozdemir-Sonmez

Reputation: 697

Dot file add graph attributes programmatically

I am creating a dot file (graphviz file automatically) using python code. I am having difficulty to add the following attributes, such as size splines, rankdir etc.., so I have to add them manually each time. Can someone show me how to add these programmatically?

//part of file digraph { splines=spline; rankdir=same node [fixedsize=true, configuration="cropping", fontsize=60, width=10, height=4, penwidth=5, size="Fit Node Size"] edge [fontsize=40] ratio="fill"; size="8.3,11.7!"; margin=0;

"1-start"; "2-access outer router";

and this is part of the code that I create the graph.

 G=nx.MultiDiGraph(directed=True)
    G.add_nodes_from([nodes_map[n] for n in nodes[:-1]])

Upvotes: 0

Views: 719

Answers (1)

sai
sai

Reputation: 1784

Perhaps this will help-

import graphviz as G

dot = G.Digraph(graph_attr={'splines':'spline', 'rankdir':'same',  'ratio':'fill', 'size':'8.3,11.7!', 'margin':'0'},
                node_attr={'fixedsize':'true', 'configuration':'cropping',  'fontsize':'60', 'width':'10', 'height':'4', 'penwidth':'5'},
                edge_attr={'fontsize':'40'})

Note: I am not sure of this size="Fit Node Size" particular attribute though

Upvotes: 2

Related Questions