您好,登錄后才能下訂單哦!
本篇內容主要講解“Python怎么使用pyecharts繪制桑基圖”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“Python怎么使用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") )
到此,相信大家對“Python怎么使用pyecharts繪制桑基圖”有了更深的了解,不妨來實際操作一番吧!這里是億速云網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。