Search code examples
graphvizdot

Include custom node attributes in plot


I need to plot a DOT graph as SVG/PDF but would like to include the node attributes for each node. For example, on the plot:

strict digraph G {

  start -> a0;
  a0 -> a3;
  j0[name=asd, weight=2];
  a3 -> j0;
  j0 -> end;
}

how to include name and weight values under j0, like (e.g.):

strict digraph G {

  start -> a0;
  a0 -> a3;
  a3 -> "j0\nname=asd\nweight=2";
  "j0\nname=asd\nweight=2" -> end;
}

Solution

  • Insert all the node attributes and values into the label attribute (https://graphviz.org/docs/attrs/label/), instead of the node name.

    strict digraph G {
    
      start -> a0;
      a0 -> a3;
      a3 -> j0
      j0 [label="j0\nname=asd\nweight=2"]
      j0-> end;
    }
    

    Giving:
    enter image description here