开发者

How can I visualize a Graph in (interactive) 3D with Python?

开发者 https://www.devze.com 2023-03-20 03:55 出处:网络
I have a Graph in Python like this one: # Each element is a tuple with coordinates (x,y,z). # The index is the id of the vertex

I have a Graph in Python like this one:

# Each element is a tuple with coordinates (x,y,z). 
# The index is the id of the vertex
vertexList = [(0,0,0),(1,0,0),(1,1,0),(0,1,0), 
               (0,0,1),(1,0,1),(1,1,1),(0,1,1)]

# Each element is a tuple with the vertex-ids and a weight (vertexId1, vertexId2, weight)
edgeList = [(0,1,1), (1,2,1), (2,3,1), (3,0,1),
               (0,4,1), 
               (4,5,1), (5,6,1), (6,7,1), (7,4,1)]
graph = (vertexList, edgeList)

This is a small example. The application I wrote uses graphs with about 100 vertexes and 300 edges.

I would like to visualize this with python, preferably with a library which is available for Ubuntu. It would be great if it were possible to move the graph in the 3D-visualisation.

What I've done so far

At the moment I use UBIGRAPH. The visualization and interaction is very good, but I can't specify coordinates for the vertexes:

def visulizeGraph(Graph):
    vertexList, edgeList = Graph
    ser开发者_StackOverflowver_url = 'http://127.0.0.1:20738/RPC2'
    server = xmlrpclib.Server(server_url)
    G = server.ubigraph;

    G.clear()
    for identifier, vertex in enumerate(vertexList):
        G.new_vertex_w_id(identifier)
    for vertex1, vertex2, weight in edgeList:
        x1, y1, z1 = vertexList[vertex1]
        x2, y2, z2 = vertexList[vertex2]

        G.new_edge(vertex1, vertex2)

matplot

I've found matplotlib, but its very big. I didn't find an example which does what I like, but I might have missed it. Its available for Ubuntu.

vtk

The same problem as with matplot. If you could give me some working examples it might be the best solution.


When you looked at matplotlib, did you see mplot3d? This may be what you require.

MPlot3D

If not, I'm sorry I probably can't help any more than that.


I've not used this myself yet (beyond running example scripts) but mayavi2 looks promising. It comes bundled with the enthought python distribution.

Also, a little of topic as it's not in your question, but networkx is pretty nice if your working with graphs in python.

Hope this helps a bit.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号