Reputation: 1993
I am trying to use the method graph_draw in graph_tool. I see references to it in the site_packages and in documentation
./cgenv/lib/python2.6/site-packages/graph_tool/draw/__init__.py: graph_draw
./cgenv/lib/python2.6/site-packages/graph_tool/draw/__init__.py:__all__ = ["graph_draw", "graphviz_draw", "fruchterman_reingold_layout",
./cgenv/lib/python2.6/site-packages/graph_tool/draw/__init__.py: >>> gt.graph_draw(g, pos=pos, output="graph-draw-fr.pdf")
./cgenv/lib/python2.6/site-packages/graph_tool/draw/__init__.py: gt.graph_draw(g, pos=pos, output="graph-draw-fr.png")
./cgenv/lib/python2.6/site-packages/graph_tool/draw/__init__.py: >>> gt.graph_draw(g, pos=pos, output="graph-draw-arf.pdf")
./cgenv/lib/python2.6/site-packages/graph_tool/draw/__init__.py: gt.graph_draw(g, pos=pos, output="graph-draw-arf.png")
./cgenv/lib/python2.6/site-packages/graph_tool/draw/__init__.py: graph_draw(u, mivs, vertex_fillcolor=mivs)
./cgenv/lib/python2.6/site-packages/graph_tool/draw/__init__.py: >>> gt.graph_draw(g, pos=pos, output="graph-draw-sfdp.pdf")
./cgenv/lib/python2.6/site-packages/graph_tool/draw/__init__.py: gt.graph_draw(g, pos=pos, output="graph-draw-sfdp.png")
./cgenv/lib/python2.6/site-packages/graph_tool/draw/__init__.py: http://www.mathematica-journal.com/issue/v10i1/graph_draw.html
./cgenv/lib/python2.6/site-packages/graph_tool/draw/__init__.py: #graph_draw(u, pos)
But when I try to access this, it does not exist...
>>> x=graph_tool.draw.GraphView
>>> x=graph_tool.draw.graph_draw()
Traceback (most recent call last):
File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd_exec.py", line 3, in Exec
exec exp in global_vars, local_vars
File "<input>", line 1, in <module>
AttributeError: 'module' object has no attribute 'graph_draw'
Am I missing something? how should i be accessing this?
Thanks!
Upvotes: 2
Views: 2190
Reputation: 6737
It seems to be an import issue... "graph_draw" function is imported from "graph_tool.all" and not from "graph_tool"
I am actually working on OSX 10.10.4 and when I import the "graph_tool" module like this:
from graph_tool.all import *
#create your graph object
g = Graph()
#add vertex
vertex_1 = g.add_vertex() #here you create a vertex
vertex_2 = g.add_vertex() #here you create a vertex
#add edge
g.add_edge(vertex_1,vertex_2) #add an edge
#draw you graph
graph_draw(
g,
output="test.png"
)
It's works !
If I follow the "import example" you provide you may try also:
from graph_tool.all import graph_draw,Graph
#create your graph object
g = Graph()
#add a vertex at least
g.add_vertex()
#draw you graph
graph_draw(
g,
output_size=(200,200),
output="test.png"
)
Please try to run one of this previous code on your computer to doublecheck if it is a module's import issue or a dependencies/installation issue
Best regards
Upvotes: 2
Reputation: 5261
Be sure you have all optional dependencies installed: pycairo, matplotlib, and gtk3 (as well as librsvg, if you are using macports).
Upvotes: 4