Ask Your Question

load a graph from a dot file

asked 2015-09-16 14:47:01 -0500

Mark Bell gravatar image

updated 2015-09-16 14:48:17 -0500

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 15:00:52 -0500

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 14:47:01 -0500

Seen: 543 times

Last updated: Sep 16 '15