可视化 | 中国历届夏季奥运会奖牌数据(树图)

简介: 可视化 | 中国历届夏季奥运会奖牌数据(树图)

大家好,我是欧K。本期给大家盘点一下中国历届夏季奥运会奖牌获取情况,并用python树图动态展示希望对你有所帮助。


先看看效果


1. 导入模块

from pyecharts.charts import Tree
from pyecharts import options as opts
from pyecharts.commons.utils import JsCode
from pyecharts.globals import ThemeType


2. 选择结构

2.1 历年奖牌数据

奖牌数据:

dic = {
'2016年': ('China', 26, 18, 26),
'2012年': ('China', 38, 27, 24),
'2008年': ('China', 51, 21, 28),
'2004年': ('China', 32, 18, 14),
'2000年': ('China', 28, 16, 14),
'1996年': ('China', 17, 22, 12),
'1992年': ('China', 16, 22, 15),
'1988年': ('China', 5, 11, 12),
'1984年': ('China', 15, 8, 9)}

翻阅新中国夏季奥运会历史,最早可上溯到1984年。

2008年,奥运会在中国北京举行,无论是在参加人数、媒体报道、赛事组织、场馆建设等多个方面,北京奥运会都可以说是一届“真正的无与伦比”的奥运会。中国代表团共派出运动员639人,参加了全部28个大项的比赛,创下中国历届奥运参赛人数之最。各项目百花齐放,中国队在赛艇、射箭、帆船帆板、拳击项目中首次拿到金牌,实现历史性突破。最终,中国取得了51金21银28铜的优异成绩,成为奥运历史上首个登上金牌榜首的亚洲国家,创造了中国代表团参加奥运会以来的最好成绩。


2.2 设置颜色样式、节点线条样式


颜色样式

color_js = """new echarts.graphic.LinearGradient(0, 0, 1, 0,
    [{offset: 0, color: '#696969'}, {offset: 1, color: '#ed1941'}], false)"""
color_js0 = """new echarts.graphic.LinearGradient(0, 0, 1, 0,
    [{offset: 0, color: '#696969'}, {offset: 1, color: '#FFD700'}], false)"""
color_js1 = """new echarts.graphic.LinearGradient(0, 0, 1, 0,
    [{offset: 0, color: '#696969'}, {offset: 1, color: '#C0C0C0'}], false)"""
color_js2 = """new echarts.graphic.LinearGradient(0, 0, 1, 0,
    [{offset: 0, color: '#696969'}, {offset: 1, color: '#8B4513'}], false)"""
color_js3 = """new echarts.graphic.LinearGradient(0, 0, 1, 0,
    [{offset: 0, color: '#FFFF00'}, {offset: 1, color: '#FF0000'}], false)"""
color_js4 = """new echarts.graphic.LinearGradient(0, 0, 1, 0,
    [{offset: 0, color: '#FFF0F5'}, {offset: 1, color: '#1E90FF'}], false)"""
color_function = """
        function (params) {
            if (params.name == '金牌') {
                return '#FFD700';
            } else if (params.name == '银牌') {
                return '#C0C0C0';
            }
            return '#8B4513';
        }
        """

节点线条样式

width = 1.5
curveness = 0.9
itemStyle1={'color':JsCode(color_js0)}
itemStyle2={'color':JsCode(color_js1)}
itemStyle3={'color':JsCode(color_js2)}
one_level_style = {'color':JsCode(color_js),'width': width, 'curveness': curveness, 'type': 'solid'}
gold_style = {'color':JsCode(color_js0),'width': width, 'curveness': curveness, 'type': 'solid'}
silver_style = {'color':JsCode(color_js1),'width': width, 'curveness': curveness, 'type': 'solid'}
bronze_style = {'color':JsCode(color_js2),'width': width, 'curveness': curveness, 'type': 'solid'}


2.3 构造父子数据

代码:

data = [{
    "name": "",
    'symbolSize':'15',
    'itemStyle':{
            'color': JsCode(color_js3),
            'borderWidth':2,
            'opacity':0.9
    } ,
    "children": [
        {
            "name": "1984年",
            'itemStyle':{'color':JsCode(color_js4)},
            'lineStyle':one_level_style,
            "children": [
                {"name": "金牌", "value": 15,'itemStyle':itemStyle1,'lineStyle':gold_style},
                {"name": "银牌", "value": 8,'itemStyle':itemStyle2,'lineStyle':silver_style},
                {"name": "铜牌", "value": 9,'itemStyle':itemStyle3,'lineStyle':bronze_style}
            ]
        },
                {
            "name": "1988年",
            'itemStyle':{'color':JsCode(color_js4)},
            'lineStyle':one_level_style,
            "children": [
                {"name": "金牌", "value": 5,'itemStyle': itemStyle1,'lineStyle':gold_style},
                {"name": "银牌", "value": 11,'itemStyle':itemStyle2,'lineStyle':silver_style},
                {"name": "铜牌", "value": 12,'itemStyle':itemStyle3,'lineStyle':bronze_style}
            ]
        },
        {
            "name": "1992年",
            'itemStyle':{'color':JsCode(color_js4)},
            'lineStyle':one_level_style,
            "children": [
                {"name": "金牌", "value": 16,'itemStyle': itemStyle1,'lineStyle':gold_style},
                {"name": "银牌", "value": 22,'itemStyle':itemStyle2,'lineStyle':silver_style},
                {"name": "铜牌", "value": 15,'itemStyle':itemStyle3,'lineStyle':bronze_style}
            ]
        },
                {
            "name": "1996年",
            'itemStyle':{'color':JsCode(color_js4)},
            'lineStyle':one_level_style,
            "children": [
                {"name": "金牌", "value": 17,'itemStyle': itemStyle1,'lineStyle':gold_style},
                {"name": "银牌", "value": 22,'itemStyle':itemStyle2,'lineStyle':silver_style},
                {"name": "铜牌", "value": 12,'itemStyle':itemStyle3,'lineStyle':bronze_style}
            ]
        },
                {
            "name": "2000年",
            'itemStyle':{'color':JsCode(color_js4)},
            'lineStyle':one_level_style,
            "children": [
                {"name": "金牌", "value": 28,'itemStyle': itemStyle1,'lineStyle':gold_style},
                {"name": "银牌", "value": 16,'itemStyle':itemStyle2,'lineStyle':silver_style},
                {"name": "铜牌", "value": 14,'itemStyle':itemStyle3,'lineStyle':bronze_style}
            ]
        },
                {
            "name": "2004年",
            'itemStyle':{'color':JsCode(color_js4)},
            'lineStyle':one_level_style,
            "children": [
                {"name": "金牌", "value": 32,'itemStyle': itemStyle1,'lineStyle':gold_style},
                {"name": "银牌", "value": 18,'itemStyle':itemStyle2,'lineStyle':silver_style},
                {"name": "铜牌", "value": 14,'itemStyle':itemStyle3,'lineStyle':bronze_style}
            ]
        },
        {
            "name": "2008年",
            'itemStyle':{'color':JsCode(color_js4)},
            'lineStyle':one_level_style,
            "children": [
                {"name": "金牌", "value": 51,'itemStyle': itemStyle1,'lineStyle':gold_style},
                {"name": "银牌", "value": 21,'itemStyle':itemStyle2,'lineStyle':silver_style},
                {"name": "铜牌", "value": 28,'itemStyle':itemStyle3,'lineStyle':bronze_style}
            ]
        },
        {
            "name": "2012年",
            'itemStyle':{'color':JsCode(color_js4)},
            'lineStyle':one_level_style,
            "children": [
                {"name": "金牌", "value": 38,'itemStyle': itemStyle1,'lineStyle':gold_style},
                {"name": "银牌", "value": 27,'itemStyle':itemStyle2,'lineStyle':silver_style},
                {"name": "铜牌", "value": 24,'itemStyle':itemStyle3,'lineStyle':bronze_style}
            ]
        },
        {
            "name": "2016年",
            'itemStyle':{'color':JsCode(color_js4)},
            'lineStyle':one_level_style,
            "children": [
                {"name": "金牌", "value": 26,'itemStyle': itemStyle1,'lineStyle':gold_style},
                {"name": "银牌", "value": 18,'itemStyle':itemStyle2,'lineStyle':silver_style},
                {"name": "铜牌", "value": 26,'itemStyle':itemStyle3,'lineStyle':bronze_style}
            ]
        },
    ]
}]

3. 绘制树图

代码:

t = (
        Tree(init_opts=opts.InitOpts(theme = ThemeType.CHALK,width="1000px", height="600px"))
        .add(
            "",
            data,
            pos_top="18%",
            pos_bottom="14%",
            symbol='circle',
            layout="radial",
            edge_fork_position="80%",
            symbol_size=15,
            label_opts=opts.LabelOpts(position="top",color='#00FFFF'),
            leaves_label_opts=opts.LabelOpts( position = 'top',distance = 12,vertical_align= 'left',
                                             font_size=12,color=JsCode(color_function),formatter='{b}: {c}')
            )
        .set_global_opts(
            tooltip_opts=opts.TooltipOpts(trigger="item", trigger_on="mousemove"),
            title_opts=opts.TitleOpts(title="中国历届夏季奥运会奖牌数",pos_left='center',pos_top="5%"))
    )
t.render_notebook()

效果:



也可以根据需要调整排列格式


完。

END


以上就是本期为大家整理的全部内容了,赶快练习起来吧,喜欢的朋友可以点赞、点在看也可以分享让更多人知道

相关文章
|
1月前
数据代码分享|R语言回归分析:体脂数据、公交绿色出行与全球变暖2案例
数据代码分享|R语言回归分析:体脂数据、公交绿色出行与全球变暖2案例
|
1月前
|
监控 数据可视化 数据挖掘
数据可视化第二版-拓展-和鲸网约车分析一等奖作品
数据可视化第二版-拓展-和鲸网约车分析一等奖作品
|
10月前
|
机器学习/深度学习 人工智能 编解码
登顶刊Cell:中国科学家领衔发布猕猴大脑皮层细胞三维「地图」
登顶刊Cell:中国科学家领衔发布猕猴大脑皮层细胞三维「地图」
|
数据可视化 数据挖掘 Python
看世界杯也能学画图:R语言ggplot2画热图展示不同国家历届足球世界杯的成绩
看世界杯也能学画图:R语言ggplot2画热图展示不同国家历届足球世界杯的成绩
|
传感器 算法 C语言
第十六届全国大学生智能车竞赛-国家级一等奖-全向行进组-控制开源
第十六届全国大学生智能车竞赛-国家级一等奖-全向行进组-开源控制
181 0
|
人工智能 编解码
《三十而已》太太圈拼包?AI带你穿越百年,看老上海真·名媛有多时尚
《三十而已》太太圈拼包?AI带你穿越百年,看老上海真·名媛有多时尚
297 0
|
存储 大数据 数据库
案例酷|计算“天文数字”,阿里云助力国家天文局探索太空
对太空的好奇伴随着人类文明。十亿天体数据上云,让“天文数字”的天文数据得以计算,也让每一个人都有了仰望星空、伸手摘星的可能。
案例酷|计算“天文数字”,阿里云助力国家天文局探索太空
|
监控 Java 大数据
8月27日云栖精选夜读 | 北京房租大涨?6个维度,数万条数据帮你揭穿
昨天还幻想海边别墅的年轻人,今天可能开始对房租绝望了。 8月初,有网友在“水木论坛”发帖控诉长租公寓加价抢房引起关注。据说,一名业主打算出租自己位于天通苑的三居室,预期租金7500元/月,结果被二方中介互相抬价,硬生生抬到了10800。
2449 0