我尝试使用谷歌搜索并拼凑来自许多来源的示例。这是我所拥有的:
import numpy as np
from vispy import app
from vispy import visuals
from vispy.visuals.transforms import STTransform
import networkx as nx
class Canvas(app.Canvas):
def __init__(self, **kwargs):
super().__init__(title="Simple NetworkX Graph", keys="interactive", size=(600, 600))
graph = nx.path_graph(8)
#graph = nx.adjacency_matrix(
#nx.fast_gnp_random_graph(500, 0.005, directed=True))
layout = nx.layout.circular_layout
self.matrix = nx.adjacency_matrix(graph)
self.visual = visuals.GraphVisual(
nx.adjacency_matrix(graph),
layout=layout,
line_color='white', arrow_type="angle_30",
arrow_size=30, node_symbol="disc", node_size=20,
face_color=(1, 0, 0, 0.5), border_width=0.0, animate=True,
directed=True)
self.visual.transform = STTransform((1, 1), (20, 20))
self.show()
#def on_resize(self, event):
#set_viewport(0, 0, *event.physical_size)
def on_draw(self, event):
clear(color=True, depth=True)
if __name__ == '__main__':
c = Canvas(title="Graph")
app.run()
输出是一个空白(黑色)屏幕,没有其他任何显示。
我的目标是使用 VisPy 显示一个简单的网络图。你有没有让这个工作,你能发布你的代码/相关代码吗?