pyecharts 关系图

数据显示: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")
    )

自己组装数据吧

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值