数据显示:label
数据来源:sourceID
数据目标:targetID
import pandas as pd
from pyecharts import options as opts
from pyecharts.charts import Graph
import random
def get_plot():
data = {
"nodes": [
{"color": randomcolor(), "label": "coffee-script", "attributes": {}, "y": -float(random.uniform(100, 1000)),
"x": float(random.uniform(1, 1000)),
"size": 44.131462},
{"color": randomcolor(), "label": "grunt", "attributes": {}, "y": --float(random.uniform(100, 1000)),
"x": float(random.uniform(1, 1000)),
"size": 9.959153},
{"color": randomcolor(), "label": "js2coffee", "attributes": {}, "y": --float(random.uniform(100, 1000)),
"x": float(random.uniform(1, 1000)),
"size": 9.959153}
],
"edges": [
{"sourceID": "hubot", "attributes": {}, "targetID": "coffee-script", "size": 1},
{"sourceID": "grunt", "attributes": {}, "targetID": "coffee-script", "size": 1},
{"sourceID": "js2coffee", "attributes": {}, "targetID": "coffee-script", "size": 1}
]
}
nodes = [
{
"x": node["x"],
"y": node["y"],
"name": node["label"],
"symbolSize": node["size"],
"itemStyle": {"normal": {"color": node["color"]}},
}
for node in data["nodes"]
]
print(nodes)
edges = [
{"source": edge["sourceID"], "target": edge["targetID"]} for edge in data["edges"]
]
print(edges)
(
Graph(init_opts=opts.InitOpts(width="1600px", height="800px"))
.add(
series_name="",
nodes=nodes,
links=edges,
layout="none",
is_roam=True,
is_focusnode=True,
label_opts=opts.LabelOpts(is_show=True),
linestyle_opts=opts.LineStyleOpts(width=5, curve=0.3, opacity=2),
)
.set_global_opts(title_opts=opts.TitleOpts(title="NPM Dependencies"))
.render("npm_dependencies.html")
)
自己组装数据吧