Python Graphviz – Import SVG file inside a node

Question:

I need to import a SVG image using the python librairy of graphviz.

Here is the SVG file (created with the software draw.io):

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Do not edit this file with editors other than diagrams.net -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg lon_Program FilesGraphvizbin'

path_current = os.path.dirname(__file__)
path_graph = os.path.join(path_current, "build", "graph")
path_svg = os.path.join(path_current, "test.svg")

graph = graphviz.Digraph(
    'structs', 
    filename=path_graph, 
    format="svg", 
    graph_attr={"rankdir": "LR"},
    node_attr={'shape': 'record'}
)

graph.node("test node SVG", **{
    "image": path_svg,
})
graph.view()

The image is just not showing without any error.

Asked By: Vincent Bénet

||

Answers:

The problem is the following:

It is necessary to have an empty label for the node:

graph.node("test node SVG", **{
    "image": path_svg,
    "label": ""
})

The image will display without problem then

Answered By: Vincent Bénet
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.