小白学Python(18)——pyecharts 关系图 Graph
Graph-基本示例
1 import json 2 import os 3 4 from pyecharts import options as opts 5 from pyecharts.charts import Graph, Page 6 7 8 nodes = [ 9 {"name": "结点1", "symbolSize": 10}, 10 {"name": "结点2", "symbolSize": 20}, 11 {"name": "结点3", "symbolSize": 30}, 12 {"name": "结点4", "symbolSize": 40}, 13 {"name": "结点5", "symbolSize": 50}, 14 {"name": "结点6", "symbolSize": 40}, 15 {"name": "结点7", "symbolSize": 30}, 16 {"name": "结点8", "symbolSize": 20}, 17 ] 18 links = [] 19 for i in nodes: 20 for j in nodes: 21 links.append({"source": i.get("name"), "target": j.get("name")}) 22 23 graph= ( 24 Graph() 25 .add("", nodes, links, repulsion=8000) 26 .set_global_opts(title_opts=opts.TitleOpts(title="Graph-基本示例")) 27 ) 28 graph.render()