In [1]:
import pydot
In [2]:
graph = pydot.Dot(graph_name='mygraph', graph_type='graph')
Graph attributes can be manipulated through the set_*() and get_*() methods.
In [3]:
graph.set_fontsize('12')
graph.get_fontsize()
Out[3]:
Defaults can be set for nodes and edges.
In [4]:
graph.set_node_defaults(fillcolor='blue', style='filled')
graph.get_node_defaults()
Out[4]:
Nodes, edges and subgraphs are added and deleted through the respective add_*() and del_*() methods.
In [5]:
node1 = pydot.Node(name='node1', label='My first node', shape='box')
node2 = pydot.Node(name='node2', label='My second node', color='red')
edge = pydot.Edge(src=node1, dst=node2, label='My Edge', style='dotted')
graph.add_node(node1)
graph.add_node(node2)
graph.add_edge(edge)
In [6]:
graph.write('pydot.dot')
graph.write_png('pydot.png')
Out[6]:
graph mygraph {
fontsize=12;
node [style=filled, fillcolor=blue];
node1 [shape=box, label="My first node"];
node2 [color=red, label="My second node"];
node1 -- node2 [style=dotted, label="My Edge"];
}
Check pages 10 to 12 of the dot User's Manual for all attributes.
In [ ]: