I have a very simple graph that I want to plot as svg. For example:
# graph.dot
graph {
a -- b;
b -- c;
}
I am currently using pydot to read the file and then generate the svg file as follows:
import pydot
graphs = pydot.graph_from_dot_file('graph.dot')
graphs[0].write_svg('graph.svg') # there is only 1 graph so the 0 index.
However, I need to do this without the need of intermediate files graph.dot
and graph.svg
. I have the code content of graph.dot
in a string, corresponding to which I need the svg output in string.
I need something like:
graph_dot = "... ..." # string, I have this
graph_svg = convert_dot_to_svg(graph_dot)
# i need something like convert_dot_to_svg()
My question is not limited to pydot only. If anyone knows a web api using which I can do this, then also it will do.
Thanks a Lot, in advance.
io
to take input. But how to replace thewrite_svg
function? – Catarinacatarrh.write_svg
accepts an open file handle instead of a file name, then it will "just work" if you supply it a StringIO or BytesIO object. If you've never used theio
module before, I suggest you study the docs & do a few experiments; it's a very useful module. – Roentgenotherapy