Ask Your Question
1

load a graph from a dot file

asked 2015-09-16 21:47:01 +0100

Mark Bell gravatar image

updated 2015-09-16 21:48:17 +0100

Sage allows me to get the representation of a Graph, G, in the dot language by using the method

G.graphviz_string()

I can even have this string written directly to a file by using:

G.graphviz_to_file_named('my_graph_file.dot')

Is there a way of reloading G from such a file? I tried doing

G = Graph('my_graph_file.dot')

G = Graph(open('my_graph_file.dot'))

G = Graph(open('my_graph_file.dot').read())

Where the contents of 'my_graph_file.dot' are:

graph MyGraph{

foo -- {bar}

bar -- {foo; bas}

bas -- {bar}

}

But none of these worked.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2015-09-16 22:00:52 +0100

Nathann gravatar image

This should work:

sage: import networkx
sage: g = Graph(networkx.read_dot('your_dot_file.dot'))

Currently you can write .dot files with Graph.export_to_file but not read them yet. We have "been about to write it" several times now, gut given that none of us apparently needs it, it still isn't actual code.

If you want to start contributing to Sage, that's a good starting point: useful contribution, and not technically complicated.

Nathann

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2015-09-16 21:47:01 +0100

Seen: 1,292 times

Last updated: Sep 16 '15