如何用Python可视化图形的(交互式)3D?
我在Python中有一个图形,像这样:
# 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)
这是一个小例子。我写的应用程序使用的图形大约有100个顶点和300条边。
我想用Python来可视化这个图形,最好是能在Ubuntu上使用的库。如果能在3D可视化中移动图形,那就更好了。
到目前为止我做了什么
目前我在使用UBIGRAPH。它的可视化和交互效果很好,但我无法为顶点指定坐标:
def visulizeGraph(Graph):
vertexList, edgeList = Graph
server_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
我发现了matplotlib,但它的体积很大。我没有找到一个符合我需求的例子,但可能是我没找到。这个库在Ubuntu上是可以用的。
vtk
和matplot一样的问题。如果你能给我一些有效的例子,那可能是最好的解决方案。