Question

I haven't been able to find a way to draw nodes with ports in pydot: neither in the documentation nor in examples on the web.

Is there a way to draw the following graph using pydot?

diagram:

          +-----------+
          |   | G |   |
          +-----------+
           /         \
          /           \
   +-----------+  +-----------+
   |   | E |   |  |   | R |   |
   +-----------+  +-----------+

dot code:

digraph g {
 node [shape = record,height=.1];
 node0[label = "<f0> |<f1> G|<f2> "];
 node1[label = "<f0> |<f1> E|<f2> "];
 node2[label = "<f0> |<f1> R|<f2> "];
 "node0":f2 -> "node2":f1;
 "node0":f0 -> "node1":f1;
}

Thanks!

Was it helpful?

Solution

Try adding label attributes like this:

In [1]: import pydot

In [2]: N = pydot.Dot()

In [3]: N.set_node_defaults(shape='record')

In [4]: p = pydot.Node('node0', label = "<f0> |<f1> G|<f2> ")

In [5]: N.add_node(p)

In [6]: N.write_dot('foo.dot')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top