from pyecharts import Graph
import pandas as pd
def create_nodes(relation_table):
table_list
= list(pd.concat([relation_table['SOURCE_TABLE_NAME'],relation_table['TARGET_TABLE_NAME']]).unique())
nodes =
[]
for i in table_list:
temp_nodes = {}
temp_nodes['name'] = i
temp_nodes['symbolSize'] = 30
temp_nodes['value'] = i
nodes.append(temp_nodes)
return nodes
def create_link(relation_table):
relation_table['CONNECT_COLUMN'] = relation_table['CONNECT_COLUMN'].str[:] + ','
link_df =
relation_table.groupby(['SOURCE_TABLE_NAME','TARGET_TABLE_NAME']).sum()
link_df['CONNECT_COLUMN'] = link_df['CONNECT_COLUMN'].str[:-1]
link_df.reset_index(inplace=True)
link_list =
[]
for index,row in link_df.iterrows():
temp_link = {}
temp_link['source'] = row[0]
temp_link['target'] = row[1]
temp_link['value'] = row[2]
link_list.append(temp_link)
return link_list
if __name__ == '__main__':
relation_table = pd.read_excel('数据字典.xlsx',sheet_name='血缘关系表')
relation_table = relation_table[['SOURCE_TABLE_NAME','TARGET_TABLE_NAME','CONNECT_COLUMN']]
graph =
Graph("关系图-力引导布局示例", width=1920, height=1080)
graph.add("",
create_nodes(relation_table),
create_link(relation_table),
graph_edge_length=400, #
标准连接距离
repulsion=8000,
# graph_layout="force",
graph_layout="circular",
is_label_show=True,
label_text_color='black',
line_curve=0.2, #
连接线弯曲程度
graph_edge_symbol=['roundRect', 'arrow'], #
连接线类型(箭头)
# line_color = '#8000ff', #
连接线颜色
graph_repulsion=800, #
图例之间的斥力距离
symbol='roundRect', #
图例形状
tooltip_formatter="{c}" #
标签显示模式
)
graph.render()
数据字典例子

效果例子


加载中,请稍候......