加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

血缘关系图

(2019-02-15 11:45:24)
标签:

python

分类: 报告处理

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()


 数据字典例子

血缘关系图
效果例子

血缘关系图
血缘关系图

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有