digraph test {
node [shape=plain];
n1 [label=<
<table border="1" cellborder="0" cellspacing="0">
<tr><td align="center"><b>Not centered when using default renderer for SVG</b></td></tr>
<tr><td align="text">Lorem ipsum</td></tr>
</table> >];
}
The graphviz documentation specifies that "In addition, all of these markups are currently only available via the cairo and svg renderers."
Indeed, when I render via the command line with dot -Tsvg ./test.dot -o test1.svg
, I get a wrong result with the text not centered in the node.
Whereas when I specify the renderer dot -Tsvg:svg ./test.dot -o test2.svg
, everything works well.
Now the problem is that calling G.draw('test3.svg', prog='dot')
probably calls the first command, which produces the wrongly aligned result.
I tried to specify the renderer with G.draw('test4.svg', prog='dot', args='-Tsvg:svg')
or G.draw('test5.svg', prog='dot', format='svg:svg')
but in both cases the produced svg is invalid (there's two <?xml ...> tags for some reason).
So is there a way to specify the renderer via pygraphviz? Or should I dump the graph in a .dot file and call dot with subprocess.run and the correct arguments?
Thanks
After checking PyGraphviz's source code, I managed to make it work with G.draw("test.svg", prog= 'dot', format='svg:cairo')
.
The format argument is deduced from the filename when it's not provided which caused Dot to output the graph twice in the same SVG file.