94

How to change the size of edge in dot (graphviz)? I would like to make some edges "bolded".

Stephane Rolland
  • 34,892
  • 31
  • 111
  • 159
name
  • 4,385
  • 4
  • 23
  • 35

2 Answers2

138

I wanted to supplement shuvalov's answer. penwidth is indeed the correct command. Additionally, in shuvalov's answer penwidth is both a node and an edge property--also correct.

The distinction i wanted to make:

  • penwidth, when used as a node property (e.g., "NodeA" [penwidth = 5]) affects the border line weight for that node

  • penwidth, when used as a edge property affects the line weight of the edge (default value is "1", specifying penwidth=2 will make the edge appear in bold type

  • if you want to change the line weight of an edge, you do not need to change penwidth for the two nodes connected by that edge (as shuvalev's answer might suggest)

  • for a directed graph (the edges have a direction) you might also wish to change the size/weight of the arrowhead and arrowtail, along with the edge weight, so that all three remain proportional

  • the length of an edge can be changed by setting the weight property, as elsewhere, the default value is 1.0; increasing that value increases the cost of stretching this edge during rendering (i.e., the drawing algorithm applies a higher penalty to solutions in which this edge is longer); notice that the edge from 1 to 4 is shorter than the edge from 1 to 2.

The following code should illustrate all of this. The rendered graph is shown below the code.

digraph {
    /* declare the node & style them */
    "Node 1" [shape=diamond, penwidth=3, style=filled, fillcolor="#FCD975"];
    "Node 2" [style=filled,fillcolor="#9ACEEB" ];
    "Node 3" [shape=diamond, style=filled, fillcolor="#FCD975" ];
    "Node 4" [style=filled, fillcolor="#9ACEEB" ]

    /* declare the edges & style them */
    "Node 1" -> "Node 2" [dir=none, weight=1, penwidth=3] ;
    "Node 1" -> "Node 3" [dir=none, color="#9ACEEB"] ;
    "Node 1" -> "Node 4" [arrowsize=.5, weight=2.]
}

enter image description here

Daniel Jonsson
  • 2,483
  • 3
  • 36
  • 58
doug
  • 65,292
  • 23
  • 156
  • 195
  • For some reason the `weight` property isn't changing anything for me. The rest is super helpful, though…thanks! – clozach Feb 24 '18 at 06:21
  • This was very helpful, in particular with the image - helped me understand the relationship here. The graphviz syntax is a bit peculiar, so such nice images really helped a lot. The only part, if I would change in the above, would be to add a bit more of an explanation in regards to penwidth, because right now the lines are all bold (I changed that, thanks to the above), but the border around the individual nodes are not thicker, which I initially wanted to do. I may get to solve this problem eventually, but in the event that I forget to publish the solution here, I just add this instead. :) – shevy Dec 23 '19 at 04:16
22

try this:

"NodeA" [ penwidth = 5]
"NodeB" [ penwidth = 5]
NodeA->NodeB [ penwidth = 3]
shuvalov
  • 4,085
  • 2
  • 16
  • 17