画图神器pyecharts-河流图

共 4974字,需浏览 10分钟

 ·

2020-12-18 11:29

              


一、概述

河流图(stream chart),是堆叠面积图的一个变种,,是堆积面积图的一种变形,通过“流动”的形状来展示不同类别的数据随时间的变化情况。但不同于堆积面积图,河流图并不是将数据描绘在一个固定的、笔直的轴上(堆积图的基准线就是x轴),而是将数据分散到一个变化的中心基准线上(该基准线不一定是笔直的)。

 

 

二、案例

在浏览金融时报的信息图表时,注意到一个疫情图很吸引眼球,就是下面这张图:

             

 

各国新冠疫情发展状况

             

 

冬季奥林匹克运动会奖牌获得者国家分布

             

 

以下图为例,作品《音曲繁美》就采用了这种河流图,它每一条的宽窄代表了音乐在特定年代流行的程度,用不同的颜色去区分不同的音乐,图表最后形成水流状的样子。

 

             

             

 

2008年2月,《纽约时报》发布了一个最典型、最著名的河流图的例子《电影的衰退和流动:过去20年的电影票房收入》,描述了从1986年1月到2008年2月期间,所有电影的上映时间以及期间的周票房变化。在这个河流图中,流形状的宽度代表了某部电影的周票房,流形状的起始是由电影的上映时间决定的。颜色由电影的总票房决定,票房就是电影的“附加定量”,颜色越深代表了电影最终票房越高。

 

             

 

三、pyecharts绘图

import pyecharts.options as optsfrom pyecharts.charts import ThemeRiver

x_data = ["DQ", "TY", "SS", "QG", "SY", "DD"]y_data = [ ["2015/11/08", 10, "DQ"], ["2015/11/09", 15, "DQ"], ["2015/11/10", 35, "DQ"], ["2015/11/11", 38, "DQ"], ["2015/11/12", 22, "DQ"], ["2015/11/13", 16, "DQ"], ["2015/11/14", 7, "DQ"], ["2015/11/15", 2, "DQ"], ["2015/11/16", 17, "DQ"], ["2015/11/17", 33, "DQ"], ["2015/11/18", 40, "DQ"], ["2015/11/19", 32, "DQ"], ["2015/11/20", 26, "DQ"], ["2015/11/21", 35, "DQ"], ["2015/11/22", 40, "DQ"], ["2015/11/23", 32, "DQ"], ["2015/11/24", 26, "DQ"], ["2015/11/25", 22, "DQ"], ["2015/11/26", 16, "DQ"], ["2015/11/27", 22, "DQ"], ["2015/11/28", 10, "DQ"], ["2015/11/08", 35, "TY"], ["2015/11/09", 36, "TY"], ["2015/11/10", 37, "TY"], ["2015/11/11", 22, "TY"], ["2015/11/12", 24, "TY"], ["2015/11/13", 26, "TY"], ["2015/11/14", 34, "TY"], ["2015/11/15", 21, "TY"], ["2015/11/16", 18, "TY"], ["2015/11/17", 45, "TY"], ["2015/11/18", 32, "TY"], ["2015/11/19", 35, "TY"], ["2015/11/20", 30, "TY"], ["2015/11/21", 28, "TY"], ["2015/11/22", 27, "TY"], ["2015/11/23", 26, "TY"], ["2015/11/24", 15, "TY"], ["2015/11/25", 30, "TY"], ["2015/11/26", 35, "TY"], ["2015/11/27", 42, "TY"], ["2015/11/28", 42, "TY"], ["2015/11/08", 21, "SS"], ["2015/11/09", 25, "SS"], ["2015/11/10", 27, "SS"], ["2015/11/11", 23, "SS"], ["2015/11/12", 24, "SS"], ["2015/11/13", 21, "SS"], ["2015/11/14", 35, "SS"], ["2015/11/15", 39, "SS"], ["2015/11/16", 40, "SS"], ["2015/11/17", 36, "SS"], ["2015/11/18", 33, "SS"], ["2015/11/19", 43, "SS"], ["2015/11/20", 40, "SS"], ["2015/11/21", 34, "SS"], ["2015/11/22", 28, "SS"], ["2015/11/23", 26, "SS"], ["2015/11/24", 37, "SS"], ["2015/11/25", 41, "SS"], ["2015/11/26", 46, "SS"], ["2015/11/27", 47, "SS"], ["2015/11/28", 41, "SS"], ["2015/11/08", 10, "QG"], ["2015/11/09", 15, "QG"], ["2015/11/10", 35, "QG"], ["2015/11/11", 38, "QG"], ["2015/11/12", 22, "QG"], ["2015/11/13", 16, "QG"], ["2015/11/14", 7, "QG"], ["2015/11/15", 2, "QG"], ["2015/11/16", 17, "QG"], ["2015/11/17", 33, "QG"], ["2015/11/18", 40, "QG"], ["2015/11/19", 32, "QG"], ["2015/11/20", 26, "QG"], ["2015/11/21", 35, "QG"], ["2015/11/22", 40, "QG"], ["2015/11/23", 32, "QG"], ["2015/11/24", 26, "QG"], ["2015/11/25", 22, "QG"], ["2015/11/26", 16, "QG"], ["2015/11/27", 22, "QG"], ["2015/11/28", 10, "QG"], ["2015/11/08", 10, "SY"], ["2015/11/09", 15, "SY"], ["2015/11/10", 35, "SY"], ["2015/11/11", 38, "SY"], ["2015/11/12", 22, "SY"], ["2015/11/13", 16, "SY"], ["2015/11/14", 7, "SY"], ["2015/11/15", 2, "SY"], ["2015/11/16", 17, "SY"], ["2015/11/17", 33, "SY"], ["2015/11/18", 40, "SY"], ["2015/11/19", 32, "SY"], ["2015/11/20", 26, "SY"], ["2015/11/21", 35, "SY"], ["2015/11/22", 4, "SY"], ["2015/11/23", 32, "SY"], ["2015/11/24", 26, "SY"], ["2015/11/25", 22, "SY"], ["2015/11/26", 16, "SY"], ["2015/11/27", 22, "SY"], ["2015/11/28", 10, "SY"], ["2015/11/08", 10, "DD"], ["2015/11/09", 15, "DD"], ["2015/11/10", 35, "DD"], ["2015/11/11", 38, "DD"], ["2015/11/12", 22, "DD"], ["2015/11/13", 16, "DD"], ["2015/11/14", 7, "DD"], ["2015/11/15", 2, "DD"], ["2015/11/16", 17, "DD"], ["2015/11/17", 33, "DD"], ["2015/11/18", 4, "DD"], ["2015/11/19", 32, "DD"], ["2015/11/20", 26, "DD"], ["2015/11/21", 35, "DD"], ["2015/11/22", 40, "DD"], ["2015/11/23", 32, "DD"], ["2015/11/24", 26, "DD"], ["2015/11/25", 22, "DD"], ["2015/11/26", 16, "DD"], ["2015/11/27", 22, "DD"], ["2015/11/28", 10, "DD"],]



( ThemeRiver(init_opts=opts.InitOpts(width="1600px", height="800px")) .add( series_name=x_data, data=y_data, singleaxis_opts=opts.SingleAxisOpts( pos_top="50", pos_bottom="50", type_="time" ), ) .set_global_opts( tooltip_opts=opts.TooltipOpts(trigger="axis", axis_pointer_type="line") ) .render("theme_river.html")

             

   

推荐阅读:
画图神器pyecharts-桑基图
画图神器pyecharts-水球图
画图神器pyecharts-旭日图


扫描关注本号↓


浏览 56
点赞
评论
收藏
分享

手机扫一扫分享

分享
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

分享
举报