用Python制作交互式知识图 使用 NetworkX 和 Plotly 创建交互式知识图,并探索不同的布局(教程含源码)

让我们使用 NetworkX 和 Plotly 使其具有交互性。

创建知识图谱

首先,我们定义代表知识图谱中关系的数据。我们有三个列表:head、relation和tail,分别表示起始实体、实体之间的关系和结束实体。我们从定义的列表创建一个数据框,并使用 NetworkX 创建关系的图形表示。

import pandas as pd
import networkx as nx
import plotly.graph_objects as go

# Define the heads, relations, and tails
head = ['drugA', 'drugB', 'drugC', 'drugD', 'drugA', 'drugC', 'drugD', 'drugE', '基因1', '基因2','基因3', '基因4', '基因50', '基因2', '基因3', '基因4']
#relation = ['treats', 'treats', 'treats', 'treats', 'inhibits', 'inhibits', 'inhibits', 'inhibits', 'associated', 'associated', 'associated', 'associated', 'associated', 'interacts', 'interacts', 'interacts']

relation = [ '治疗' , '治疗

猜你喜欢

转载自blog.csdn.net/iCloudEnd/article/details/132729789