4 Star 7 Fork 0

milohaha/GrayScope

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
visual.py 1.20 KB
一键复制 编辑 原始数据 按行查看 历史
milohaha 提交于 2024-02-03 14:59 . Initial Commit
from pyvis.network import Network
def plot_networkx(graph, save_path=None, front_end_metric=None, root_cause_path=None):
if root_cause_path:
for node in root_cause_path:
if node in list(graph.nodes()):
graph.nodes.get(node).update({"color": "#dd4b39"})
if front_end_metric and front_end_metric in list(graph.nodes()):
graph.nodes.get(front_end_metric).update({"color": "#ffa500"})
# pyvis画图
pyvis_g = Network(width=1920, height=800, select_menu=True,
filter_menu=True, directed=True)
pyvis_g.from_nx(graph)
pyvis_g.toggle_physics(True) #允许更流畅的图形交互默认=True
# pyvis_g.show_buttons(filter_=['nodes', 'edges', 'physics']) #页面布局按钮
if save_path:
pyvis_g.show(save_path)
else:
pyvis_g.show("figure.html")
# # networkx画图
# import matplotlib.pyplot as plt
# pos = nx.circular_layout(graph) # 圆形布局,起到美化作用
# nx.draw(graph, pos, with_labels=True, font_weight="bold")
# plt.title("DiGraph")
# if save_path:
# plt.savefig(save_path.replace(".html", ".png"))
# else:
# plt.savefig("demo.png")
return graph
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/milohaha/grayscope.git
git@gitee.com:milohaha/grayscope.git
milohaha
grayscope
GrayScope
master

搜索帮助