Ask Your Question

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


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


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

G = Graph('')

G = Graph(open(''))

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

Where the contents of '' 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

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

Nathann gravatar image

This should work:

sage: import networkx
sage: g = Graph(networkx.read_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.


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


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

Seen: 1,171 times

Last updated: Sep 16 '15