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.
After spending some more time looking at the available methods on pydot
object and graph
object, it could be figured out:
The following code works:
import pydot
dot_string = """graph {
a -- b;
b -- c;
} """
graphs = pydot.graph_from_dot_data( dot_string )
svg_string = graphs[0].create_svg()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With