Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Annotate DOT graphs with images

I'm using PyDot to generate Graphviz/dot graphs in python. I would like to annotate my nodes and edges with images read from files, I've found in the documentation how to put an image as a node, but not how to put an image under a node or even less an edge.

http://www.graphviz.org/doc/info/attrs.html

http://www.graphviz.org/doc/info/shapes.html

http://www.graphviz.org/Documentation/html/shapehowto.html

Does anybody know how to do that?

like image 756
Shnippoo Avatar asked Mar 24 '26 10:03

Shnippoo


2 Answers

You can use HTML in the labels for nodes and edges. You can find details here: http://www.graphviz.org/doc/info/shapes.html#html

Basically you can say something

"a" -> "b" [label = <<TABLE><TR><TD><IMG SRC="path/to/picture"/></TD></TR></TABLE>>]

You can add as many rows and columns as you want in the html labels. It's a little more verbose than standard text labels, but you can do a bit more with them.

like image 107
Brad Avatar answered Mar 28 '26 03:03

Brad


One method which can work in cases where edges will always be drawn in the same position is to create a PNG with a transparent background and position the icon in the same place that your edge will be drawn, or use the labeldistance/labelangle attributes to move. I'm not familiar with PyDot but using SQL I would create a case to determine whether or not the image is displayed on the node..

Problem with this method is that the graphs which I'm working with are always positioned differently and will never be the same, so in an ideal case I'd like to add the image to the edge label, or under/to the right of the edge label etc. Did you ever manage to find a workaround?

like image 25
robbith Avatar answered Mar 28 '26 02:03

robbith



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!