怎样利用pyecharts绘制一个复杂的桑基图
Admin 2022-07-28 群英技术资讯 996 次浏览
这篇文章主要讲解了“怎样利用pyecharts绘制一个复杂的桑基图”,文中的讲解内容简单、清晰、详细,对大家学习或是工作可能会有一定的帮助,希望大家阅读完这篇文章能有所收获。下面就请大家跟着小编的思路一起来学习一下吧。桑基图(Sankey diagram),即桑基能量分流图,也叫桑基能量平衡图。它是一种特定类型的流程图,图中延伸的分支的宽度对应数据流量的大小,通常应用于 能源、材料成分、 金融等数据的可视化分析。因1898年Matthew Henry Phineas Riall Sankey绘制的“ 蒸汽机的能源效率图”而闻名,此后便以其名字命名为“桑基图”。
桑基图最明显的特征就是,始末端的分支宽度总和相等,即所有主支宽度的总和应与所有分出去的分支宽度的总和相等,保持能量的平衡。
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="标题"))
.render("桑基图.html")
)

from pyecharts import options as opts
from pyecharts.charts import Sankey
colors = [
"#67001f",
"#b2182b",
"#d6604d",
"#f4a582",
"#fddbc7",
"#d1e5f0",
"#92c5de",
"#4393c3",
"#2166ac",
"#053061",
]
nodes = [
{"name": "a"},
{"name": "b"},
{"name": "a1"},
{"name": "b1"},
{"name": "c"},
{"name": "e"},
]
links = [
{"source": "a", "target": "a1", "value": 5},
{"source": "e", "target": "b", "value": 3},
{"source": "a", "target": "b1", "value": 3},
{"source": "b1", "target": "a1", "value": 1},
{"source": "b1", "target": "c", "value": 2},
{"source": "b", "target": "c", "value": 1},
]
c = (
Sankey()
.set_colors(colors)
.add(
"sankey",
nodes=nodes,
links=links,
pos_bottom="10%",
focus_node_adjacency="allEdges",
orient="vertical",
linestyle_opt=opts.LineStyleOpts(opacity=0.2, curve=0.5, color="source"),
label_opts=opts.LabelOpts(position="top"),
)
.set_global_opts(
title_opts=opts.TitleOpts(title="标题"),
tooltip_opts=opts.TooltipOpts(trigger="item", trigger_on="mousemove"),
)
.render("复杂桑基图.html")
)

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
这篇文章给大家分享的是如何使用python实现文件批量重命名的方法,在我们需要对多文件重新命名的时候,小编觉得这个方法比较实用,需要的朋友可以参考,接下来一起跟随小编看看吧。
这篇文章主要介绍了python调用kubernetesAPI简单使用方法,K8s也提供API接口,提供这个接口的是管理节点的apiserver组件,下文更多相关内容,需要的小伙伴可以参考一下
dataframe设置index重命名dataframe的index 方法1:直接赋值法方法2:map方法3:rename自定义map函数处理dataframedataframe设置indexDataFrame.set_index(keys, drop=True,
这篇文章主要给大家分享了python内存泄漏排查技巧总结,工作过程中服务难免遇到内存泄漏问题,下面文章就给大家总结一些排查下技巧,具有一定的参考价值,需要的朋友可以参考一下
这篇文章主要介绍了Django表单外键选项初始化的问题及解决方法,需本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,要的朋友可以参考下
成为群英会员,开启智能安全云计算之旅
立即注册关注或联系群英网络
7x24小时售前:400-678-4567
7x24小时售后:0668-2555666
24小时QQ客服
群英微信公众号
CNNIC域名投诉举报处理平台
服务电话:010-58813000
服务邮箱:service@cnnic.cn
投诉与建议:0668-2555555
Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008