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.
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
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.
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