Python绘制桑基图Sankey,Pyecharts不显示html页面,桑基图只显示标题,原因总结

Python绘制桑基图Sankey,Pyecharts不显示html页面,桑基图只显示标题,原因总结

说说使用上的三点注意:

1.nodes中的"name"不要重新命名,否则会不识别,导致没有图

2.links中source和target对应的值一定要在nodes的name对应的值中,否则图中会不显示(但是不会报错)

3.links中source和target对应的值不能相同,否则图不显示

主要参考: 桑基图官方文档

# official
from pyecharts import options as opts
from pyecharts.charts import Sankey

nodes = [
    {"name": "category1"},
    {"name": "category2"},
    {"name": "category3"},
    {"name": "category4"},
    {"name": "category5"},
    {"name": "category6"},
]

links = [
    {"source": "category1", "target": "category2", "value": 10},
    {"source": "category2", "target": "category3", "value": 15},
    {"source": "category3", "target": "category4", "value": 20},
    {"source": "category5", "target": "category6", "value": 25},
]
c = (
    Sankey()
    .add(
        "sankey",
        nodes,
        links,
        linestyle_opt=opts.LineStyleOpts(opacity=0.2, curve=0.5, color="source"),
        label_opts=opts.LabelOpts(position="right"),
    )
    .set_global_opts(title_opts=opts.TitleOpts(title="Sankey-基本示例"))
    .render("sankey_base.html")
)

参考1:Pyecharts 1.7.0制作图表,运行生成的html文件用浏览器打开空白问题(以桑基图为例)
主要用于无法访问html中的"https://assets.pyecharts.org/assets/echarts.min.js",可在无法联网时使用
方法为:手动定制下载echarts.min.js,复制到本地,然后修改.html文件 “https://assets.pyecharts.org/assets/echarts.min.js"为相对路径”./echarts.min.js"

  • 3
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值