Perhaps not quite what you intend to do, but you can use pygraphviz and print the graph to a file:
import pygraphviz as pgv G=pgv.AGraph() G.add_edge('1','2') G.layout() G.draw('file.png')
(or you can just import the .dot file with G = pgv.AGraph ('file.dot'))
Then you can always use Image or openCV to download your file and display it in the viewer.
I don't think pygraphviz allows you this directly.
EDIT:
I recently learned another way and remembered your question: NetworkX allows you to do this. Here's how:
Or create your own graph using NetworkX directly. Conveniently, most NetworkX commands are the same as in pygraphviz. Then just send to matplotlib and write it there:
import networkx as nx import matplotlib.pyplot as plt G = nx.Graph() G.add_edge('1','2') nx.draw(G) plt.show()
Or you can import your .dot file through pygraphviz and then convert it to a networkx object:
import pygraphviz as pgv import networkx as nx import matplotlib.pyplot as plt Gtmp = pgv.AGraph('file.dot') G = nx.Graph(Gtmp) nx.draw(G) plt.show()
So now you have more options :)
source share