pyecharts从入门到精通-地图专题Map-带时间轴与网格的复杂绘图

news2025/1/16 3:42:34

文章目录

    • 参考
    • 安装与查看pyecharts
    • 地图实现-Geo
      • 导入依赖
      • 生成数据集
        • 生成2013-2018年的各个省份GDP数据
        • 生成2013-2018年的时间列表
        • 生成2013-2018年的总GDP
        • 设置visulmap的最大最小值范围
      • 生成2013年的网格组合图
        • 提取2013年的数据测试
        • 绘制map地图
        • 绘制折线图line
        • 绘制折线图bar
        • 绘制折线图pie
        • 生成2013年网格组合图
      • 生成包含timeline的网格组合图
      • 完整代码如下:

参考

官方文档:https://pyecharts.org/#/zh-cn/quickstart
Python使用Pyecharts画Geo地图,如何显示具体地点名称
pyecharts世界地图用:国家中英文对照表.xlsx
Map中的地理坐标问题
https://gallery.pyecharts.org/#/Map/china_gdp_from_1993_to_2018

安装与查看pyecharts

安装pyecharts

pip install pyecharts==2.0.3
# Successfully installed prettytable-3.7.0 pyecharts-2.0.3 simplejson-3.19.1

查看版本

import pyecharts
print(pyecharts.__version__) 
# 2.0.3

地图实现-Geo

pyecharts的地图实现包括:

Geo:地理坐标系
Map:地图
BMap:百度地图

本部分完成Map实现,并带有grid与timeline等多种组合技巧,代码来源于:
https://gallery.pyecharts.org/#/Map/china_gdp_from_1993_to_2018

导入依赖

from typing import List

import pyecharts.options as opts
from pyecharts.globals import ThemeType
from pyecharts.commons.utils import JsCode
from pyecharts.charts import Timeline, Grid, Bar, Map, Pie, Line

生成数据集

生成2013-2018年的各个省份GDP数据

数据为中国GDP数据,数据集如下:

"""
Gallery 使用 pyecharts 1.3.0
From pyecharts 交流分享群 -- 郭昱
"""
data = [
    {
        "time": "2013年",
        "data": [
            {"name": "广东省", "value": [62475.0, 9.85, "广东省"]},
            {"name": "江苏省", "value": [59753.0, 9.42, "江苏省"]},
            {"name": "山东省", "value": [55230.0, 8.71, "山东省"]},
            {"name": "浙江省", "value": [37757.0, 5.95, "浙江省"]},
            {"name": "河南省", "value": [32191.0, 5.07, "河南省"]},
            {"name": "河北省", "value": [28443.0, 4.48, "河北省"]},
            {"name": "辽宁省", "value": [27213.0, 4.29, "辽宁省"]},
            {"name": "四川省", "value": [26392.0, 4.16, "四川省"]},
            {"name": "湖北省", "value": [24792.0, 3.91, "湖北省"]},
            {"name": "湖南省", "value": [24622.0, 3.88, "湖南省"]},
            {"name": "福建省", "value": [21868.0, 3.45, "福建省"]},
            {"name": "上海市", "value": [21818.0, 3.44, "上海市"]},
            {"name": "北京市", "value": [19801.0, 3.12, "北京市"]},
            {"name": "安徽省", "value": [19229.0, 3.03, "安徽省"]},
            {"name": "内蒙古", "value": [16917.0, 2.67, "内蒙古"]},
            {"name": "陕西省", "value": [16205.0, 2.55, "陕西省"]},
            {"name": "黑龙江省", "value": [14455.0, 2.28, "黑龙江省"]},
            {"name": "广西壮族自治区", "value": [14450.0, 2.28, "广西壮族自治区"]},
            {"name": "天津市", "value": [14442.0, 2.28, "天津市"]},
            {"name": "江西省", "value": [14410.0, 2.27, "江西省"]},
            {"name": "吉林省", "value": [13046.0, 2.06, "吉林省"]},
            {"name": "重庆市", "value": [12783.0, 2.02, "重庆市"]},
            {"name": "山西省", "value": [12665.0, 2.0, "山西省"]},
            {"name": "云南省", "value": [11832.0, 1.87, "云南省"]},
            {"name": "新疆维吾尔自治区", "value": [8444.0, 1.33, "新疆维吾尔自治区"]},
            {"name": "贵州省", "value": [8087.0, 1.27, "贵州省"]},
            {"name": "甘肃省", "value": [6331.0, 1.0, "甘肃省"]},
            {"name": "海南省", "value": [3178.0, 0.5, "海南省"]},
            {"name": "宁夏回族自治区", "value": [2578.0, 0.41, "宁夏回族自治区"]},
            {"name": "青海省", "value": [2122.0, 0.33, "青海省"]},
            {"name": "西藏自治区", "value": [816.0, 0.13, "西藏自治区"]},
        ],
    },
    {
        "time": "2014年",
        "data": [
            {"name": "广东省", "value": [67810.0, 9.91, "广东省"]},
            {"name": "江苏省", "value": [65088.0, 9.51, "江苏省"]},
            {"name": "山东省", "value": [59427.0, 8.68, "山东省"]},
            {"name": "浙江省", "value": [40173.0, 5.87, "浙江省"]},
            {"name": "河南省", "value": [34938.0, 5.11, "河南省"]},
            {"name": "河北省", "value": [29421.0, 4.3, "河北省"]},
            {"name": "辽宁省", "value": [28627.0, 4.18, "辽宁省"]},
            {"name": "四川省", "value": [28537.0, 4.17, "四川省"]},
            {"name": "湖北省", "value": [27379.0, 4.0, "湖北省"]},
            {"name": "湖南省", "value": [27037.0, 3.95, "湖南省"]},
            {"name": "福建省", "value": [24056.0, 3.52, "福建省"]},
            {"name": "上海市", "value": [23568.0, 3.44, "上海市"]},
            {"name": "北京市", "value": [21331.0, 3.12, "北京市"]},
            {"name": "安徽省", "value": [20849.0, 3.05, "安徽省"]},
            {"name": "内蒙古", "value": [17770.0, 2.6, "内蒙古"]},
            {"name": "陕西省", "value": [17690.0, 2.58, "陕西省"]},
            {"name": "天津市", "value": [15727.0, 2.3, "天津市"]},
            {"name": "江西省", "value": [15715.0, 2.3, "江西省"]},
            {"name": "广西壮族自治区", "value": [15673.0, 2.29, "广西壮族自治区"]},
            {"name": "黑龙江省", "value": [15039.0, 2.2, "黑龙江省"]},
            {"name": "重庆市", "value": [14263.0, 2.08, "重庆市"]},
            {"name": "吉林省", "value": [13803.0, 2.02, "吉林省"]},
            {"name": "云南省", "value": [12815.0, 1.87, "云南省"]},
            {"name": "山西省", "value": [12761.0, 1.86, "山西省"]},
            {"name": "新疆维吾尔自治区", "value": [9273.0, 1.36, "新疆维吾尔自治区"]},
            {"name": "贵州省", "value": [9266.0, 1.35, "贵州省"]},
            {"name": "甘肃省", "value": [6837.0, 1.0, "甘肃省"]},
            {"name": "海南省", "value": [3501.0, 0.51, "海南省"]},
            {"name": "宁夏回族自治区", "value": [2752.0, 0.4, "宁夏回族自治区"]},
            {"name": "青海省", "value": [2303.0, 0.34, "青海省"]},
            {"name": "西藏自治区", "value": [921.0, 0.13, "西藏自治区"]},
        ],
    },
    {
        "time": "2015年",
        "data": [
            {"name": "广东省", "value": [72813.0, 10.07, "广东省"]},
            {"name": "江苏省", "value": [70116.0, 9.7, "江苏省"]},
            {"name": "山东省", "value": [63002.0, 8.72, "山东省"]},
            {"name": "浙江省", "value": [42886.0, 5.93, "浙江省"]},
            {"name": "河南省", "value": [37002.0, 5.12, "河南省"]},
            {"name": "四川省", "value": [30053.0, 4.16, "四川省"]},
            {"name": "河北省", "value": [29806.0, 4.12, "河北省"]},
            {"name": "湖北省", "value": [29550.0, 4.09, "湖北省"]},
            {"name": "湖南省", "value": [28902.0, 4.0, "湖南省"]},
            {"name": "辽宁省", "value": [28669.0, 3.97, "辽宁省"]},
            {"name": "福建省", "value": [25980.0, 3.59, "福建省"]},
            {"name": "上海市", "value": [25123.0, 3.48, "上海市"]},
            {"name": "北京市", "value": [23015.0, 3.18, "北京市"]},
            {"name": "安徽省", "value": [22006.0, 3.04, "安徽省"]},
            {"name": "陕西省", "value": [18022.0, 2.49, "陕西省"]},
            {"name": "内蒙古", "value": [17832.0, 2.47, "内蒙古"]},
            {"name": "广西壮族自治区", "value": [16803.0, 2.32, "广西壮族自治区"]},
            {"name": "江西省", "value": [16724.0, 2.31, "江西省"]},
            {"name": "天津市", "value": [16538.0, 2.29, "天津市"]},
            {"name": "重庆市", "value": [15717.0, 2.17, "重庆市"]},
            {"name": "黑龙江省", "value": [15084.0, 2.09, "黑龙江省"]},
            {"name": "吉林省", "value": [14063.0, 1.95, "吉林省"]},
            {"name": "云南省", "value": [13619.0, 1.88, "云南省"]},
            {"name": "山西省", "value": [12766.0, 1.77, "山西省"]},
            {"name": "贵州省", "value": [10503.0, 1.45, "贵州省"]},
            {"name": "新疆维吾尔自治区", "value": [9325.0, 1.29, "新疆维吾尔自治区"]},
            {"name": "甘肃省", "value": [6790.0, 0.94, "甘肃省"]},
            {"name": "海南省", "value": [3703.0, 0.51, "海南省"]},
            {"name": "宁夏回族自治区", "value": [2912.0, 0.4, "宁夏回族自治区"]},
            {"name": "青海省", "value": [2417.0, 0.33, "青海省"]},
            {"name": "西藏自治区", "value": [1026.0, 0.14, "西藏自治区"]},
        ],
    },
    {
        "time": "2016年",
        "data": [
            {"name": "广东省", "value": [80855.0, 10.37, "广东省"]},
            {"name": "江苏省", "value": [77388.0, 9.92, "江苏省"]},
            {"name": "山东省", "value": [68024.0, 8.72, "山东省"]},
            {"name": "浙江省", "value": [47251.0, 6.06, "浙江省"]},
            {"name": "河南省", "value": [40472.0, 5.19, "河南省"]},
            {"name": "四川省", "value": [32935.0, 4.22, "四川省"]},
            {"name": "湖北省", "value": [32665.0, 4.19, "湖北省"]},
            {"name": "河北省", "value": [32070.0, 4.11, "河北省"]},
            {"name": "湖南省", "value": [31551.0, 4.04, "湖南省"]},
            {"name": "福建省", "value": [28811.0, 3.69, "福建省"]},
            {"name": "上海市", "value": [28179.0, 3.61, "上海市"]},
            {"name": "北京市", "value": [25669.0, 3.29, "北京市"]},
            {"name": "安徽省", "value": [24408.0, 3.13, "安徽省"]},
            {"name": "辽宁省", "value": [22247.0, 2.85, "辽宁省"]},
            {"name": "陕西省", "value": [19400.0, 2.49, "陕西省"]},
            {"name": "江西省", "value": [18499.0, 2.37, "江西省"]},
            {"name": "广西壮族自治区", "value": [18318.0, 2.35, "广西壮族自治区"]},
            {"name": "内蒙古", "value": [18128.0, 2.32, "内蒙古"]},
            {"name": "天津市", "value": [17885.0, 2.29, "天津市"]},
            {"name": "重庆市", "value": [17741.0, 2.27, "重庆市"]},
            {"name": "黑龙江省", "value": [15386.0, 1.97, "黑龙江省"]},
            {"name": "云南省", "value": [14788.0, 1.9, "云南省"]},
            {"name": "吉林省", "value": [14777.0, 1.89, "吉林省"]},
            {"name": "山西省", "value": [13050.0, 1.67, "山西省"]},
            {"name": "贵州省", "value": [11777.0, 1.51, "贵州省"]},
            {"name": "新疆维吾尔自治区", "value": [9650.0, 1.24, "新疆维吾尔自治区"]},
            {"name": "甘肃省", "value": [7200.0, 0.92, "甘肃省"]},
            {"name": "海南省", "value": [4053.0, 0.52, "海南省"]},
            {"name": "宁夏回族自治区", "value": [3169.0, 0.41, "宁夏回族自治区"]},
            {"name": "青海省", "value": [2572.0, 0.33, "青海省"]},
            {"name": "西藏自治区", "value": [1151.0, 0.15, "西藏自治区"]},
        ],
    },
    {
        "time": "2017年",
        "data": [
            {"name": "广东省", "value": [89705.0, 10.59, "广东省"]},
            {"name": "江苏省", "value": [85870.0, 10.14, "江苏省"]},
            {"name": "山东省", "value": [72634.0, 8.57, "山东省"]},
            {"name": "浙江省", "value": [51768.0, 6.11, "浙江省"]},
            {"name": "河南省", "value": [44553.0, 5.26, "河南省"]},
            {"name": "四川省", "value": [36980.0, 4.37, "四川省"]},
            {"name": "湖北省", "value": [35478.0, 4.19, "湖北省"]},
            {"name": "河北省", "value": [34016.0, 4.02, "河北省"]},
            {"name": "湖南省", "value": [33903.0, 4.0, "湖南省"]},
            {"name": "福建省", "value": [32182.0, 3.8, "福建省"]},
            {"name": "上海市", "value": [30633.0, 3.62, "上海市"]},
            {"name": "北京市", "value": [28015.0, 3.31, "北京市"]},
            {"name": "安徽省", "value": [27018.0, 3.19, "安徽省"]},
            {"name": "辽宁省", "value": [23409.0, 2.76, "辽宁省"]},
            {"name": "陕西省", "value": [21899.0, 2.59, "陕西省"]},
            {"name": "江西省", "value": [20006.0, 2.36, "江西省"]},
            {"name": "重庆市", "value": [19425.0, 2.29, "重庆市"]},
            {"name": "天津市", "value": [18549.0, 2.19, "天津市"]},
            {"name": "广西壮族自治区", "value": [18523.0, 2.19, "广西壮族自治区"]},
            {"name": "云南省", "value": [16376.0, 1.93, "云南省"]},
            {"name": "内蒙古", "value": [16096.0, 1.9, "内蒙古"]},
            {"name": "黑龙江省", "value": [15903.0, 1.88, "黑龙江省"]},
            {"name": "山西省", "value": [15528.0, 1.83, "山西省"]},
            {"name": "吉林省", "value": [14945.0, 1.76, "吉林省"]},
            {"name": "贵州省", "value": [13541.0, 1.6, "贵州省"]},
            {"name": "新疆维吾尔自治区", "value": [10882.0, 1.28, "新疆维吾尔自治区"]},
            {"name": "甘肃省", "value": [7460.0, 0.88, "甘肃省"]},
            {"name": "海南省", "value": [4463.0, 0.53, "海南省"]},
            {"name": "宁夏回族自治区", "value": [3444.0, 0.41, "宁夏回族自治区"]},
            {"name": "青海省", "value": [2625.0, 0.31, "青海省"]},
            {"name": "西藏自治区", "value": [1311.0, 0.15, "西藏自治区"]},
        ],
    },
    {
        "time": "2018年",
        "data": [
            {"name": "广东省", "value": [97278.0, 10.63, "广东省"]},
            {"name": "江苏省", "value": [92595.0, 10.12, "江苏省"]},
            {"name": "山东省", "value": [76470.0, 8.36, "山东省"]},
            {"name": "浙江省", "value": [56197.0, 6.14, "浙江省"]},
            {"name": "河南省", "value": [48056.0, 5.25, "河南省"]},
            {"name": "四川省", "value": [40678.0, 4.45, "四川省"]},
            {"name": "湖北省", "value": [39367.0, 4.3, "湖北省"]},
            {"name": "湖南省", "value": [36426.0, 3.98, "湖南省"]},
            {"name": "河北省", "value": [36010.0, 3.94, "河北省"]},
            {"name": "福建省", "value": [35804.0, 3.91, "福建省"]},
            {"name": "上海市", "value": [32680.0, 3.57, "上海市"]},
            {"name": "北京市", "value": [30320.0, 3.31, "北京市"]},
            {"name": "安徽省", "value": [30007.0, 3.28, "安徽省"]},
            {"name": "辽宁省", "value": [25315.0, 2.77, "辽宁省"]},
            {"name": "陕西省", "value": [24438.0, 2.67, "陕西省"]},
            {"name": "江西省", "value": [21985.0, 2.4, "江西省"]},
            {"name": "重庆市", "value": [20363.0, 2.23, "重庆市"]},
            {"name": "广西壮族自治区", "value": [20353.0, 2.23, "广西壮族自治区"]},
            {"name": "天津市", "value": [18810.0, 2.06, "天津市"]},
            {"name": "云南省", "value": [17881.0, 1.95, "云南省"]},
            {"name": "内蒙古", "value": [17289.0, 1.89, "内蒙古"]},
            {"name": "山西省", "value": [16818.0, 1.84, "山西省"]},
            {"name": "黑龙江省", "value": [16362.0, 1.79, "黑龙江省"]},
            {"name": "吉林省", "value": [15075.0, 1.65, "吉林省"]},
            {"name": "贵州省", "value": [14806.0, 1.62, "贵州省"]},
            {"name": "新疆维吾尔自治区", "value": [12199.0, 1.33, "新疆维吾尔自治区"]},
            {"name": "甘肃省", "value": [8246.0, 0.9, "甘肃省"]},
            {"name": "海南省", "value": [4832.0, 0.53, "海南省"]},
            {"name": "宁夏回族自治区", "value": [3705.0, 0.41, "宁夏回族自治区"]},
            {"name": "青海省", "value": [2865.0, 0.31, "青海省"]},
            {"name": "西藏自治区", "value": [1478.0, 0.16, "西藏自治区"]},
        ],
    },
]

生成2013-2018年的时间列表

# 生成2013-2019年的时间列表
time_list = [str(d) + "年" for d in range(2013, 2019)] 
time_list

在这里插入图片描述

生成2013-2018年的总GDP

total_num = [
    63.4,
    68.4,
    72.3,
    78,
    84.7,
    91.5,
]
total_num

在这里插入图片描述

设置visulmap的最大最小值范围

maxNum = 97300
minNum = 30

生成2013年的网格组合图

提取2013年的数据测试

# 提取2013年的数据
year = '2013年'
# data为每个年份的各个省份GDP数据    
map_data = [
    [[x["name"], x["value"]] for x in d["data"]] for d in data if d["time"] == year
][0]
print(map_data) #当输入的年份为2013时
'''
[['广东省', [62475.0, 9.85, '广东省']], ['江苏省', [59753.0, 9.42, '江苏省']], ['山东省', [55230.0, 8.71, '山东省']], 
...
['青海省', [2122.0, 0.33, '青海省']], ['西藏自治区', [816.0, 0.13, '西藏自治区']]]
'''
min_data, max_data = (minNum, maxNum)
data_mark: List = []
i = 0
for x in time_list:
    if x == year:
        data_mark.append(total_num[i])
    else:
        data_mark.append("")
    i = i + 1
print("data_mark-->",data_mark)
# data_mark--> [63.4, '', '', '', '', ''] #当输入的年份为2013时

在这里插入图片描述

绘制map地图

定义绘制地图函数get_year_chart_map:

#  生成地图 
def get_year_chart_map(year: str,map_data,min_data=0,max_data=1000):
    map_chart = (
        Map()
        .add(
            series_name="",
            data_pair=map_data,
            maptype='china',
            zoom=1,
            center=[119.5, 34.5],
            is_map_symbol_show=False,
            itemstyle_opts={
                "normal": {"areaColor": "#323c48", "borderColor": "#404a59"},
                "emphasis": {
                    "label": {"show": Timeline},
                    "areaColor": "rgba(255,255,255, 0.5)",
                },
            },
        )
        .set_global_opts(
            title_opts=opts.TitleOpts(
                title="" + str(year) + "全国分地区GPD情况(单位:亿) 数据来源:国家统计局",
                subtitle="",
                pos_left="center",
                pos_top="top",
                title_textstyle_opts=opts.TextStyleOpts(
                    font_size=25, color="rgba(255,255,255, 0.9)"
                ),
            ),
            tooltip_opts=opts.TooltipOpts(
                is_show=True,
                formatter=JsCode(
                    """function(params) {
                    if ('value' in params.data) {
                        return params.data.value[2] + ': ' + params.data.value[0];
                    }
                }"""
                ),
            ),
            visualmap_opts=opts.VisualMapOpts(
                is_calculable=True,
                dimension=0,
                pos_left="30",
                pos_top="center",
                range_text=["High", "Low"],
                range_color=["lightskyblue", "yellow", "orangered"],
                textstyle_opts=opts.TextStyleOpts(color="#ddd"),
                min_=min_data,
                max_=max_data,
            ),
        )
    )
    return map_chart
        

生成map地图测试:

map_chart = get_year_chart_map(year=year,map_data=map_data,min_data=min_data,max_data=max_data)
map_chart.render_notebook()

在这里插入图片描述

绘制折线图line

定义绘制函数get_year_chart_line:

def get_year_chart_line(year=year,map_data=map_data,min_data=min_data,max_data=max_data,data_mark=data_mark):
    line_chart = (
        Line()
        .add_xaxis(time_list)
        .add_yaxis("", total_num)
        .add_yaxis(
            "",
            data_mark,
            markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(type_="max")]),
        )
        .set_series_opts(label_opts=opts.LabelOpts(is_show=False))
        .set_global_opts(
            title_opts=opts.TitleOpts(
                title="全国GDP总量{}(单位:万亿)".format(year), pos_left="50%", pos_top="5%"
            )
        )
    )
    return line_chart

生成line测试:

line = get_year_chart_line(year=year,map_data=map_data,min_data=min_data,max_data=max_data,data_mark=data_mark)
line.render_notebook()

在这里插入图片描述

绘制折线图bar

定义绘制函数get_year_chart_bar:

def get_year_chart_bar(year=year,map_data=map_data,min_data=min_data,max_data=max_data):
    bar_x_data = [x[0] for x in map_data]
    bar_y_data = [{"name": x[0], "value": x[1][0]} for x in map_data]
    bar = (
        Bar()
        .add_xaxis(xaxis_data=bar_x_data)
        .add_yaxis(
            series_name="",
            y_axis=bar_y_data,
            label_opts=opts.LabelOpts(
                is_show=True, position="right", formatter="{b} : {c}"
            ),
        )
        .reversal_axis()
        .set_global_opts(
            xaxis_opts=opts.AxisOpts(
                max_=maxNum, axislabel_opts=opts.LabelOpts(is_show=False)
            ),
            yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(is_show=False)),
            tooltip_opts=opts.TooltipOpts(is_show=False),
            visualmap_opts=opts.VisualMapOpts(
                is_calculable=True,
                dimension=0,
                pos_left="10",
                pos_top="top",
                range_text=["High", "Low"],
                range_color=["lightskyblue", "yellow", "orangered"],
                textstyle_opts=opts.TextStyleOpts(color="#ddd"),
                min_=min_data,
                max_=max_data,
            ),
        )
    )
    
    return bar

生成bar测试:

bar = get_year_chart_bar(year=year,map_data=map_data,min_data=min_data,max_data=max_data)
bar.render_notebook()

在这里插入图片描述

绘制折线图pie

定义绘制函数get_year_chart_pie:

def get_year_chart_pie(year=year,map_data=map_data,min_data=min_data,max_data=max_data):
    pie_data = [[x[0], x[1][0]] for x in map_data]
    pie = (
        Pie()
        .add(
            series_name="",
            data_pair=pie_data,
            radius=["15%", "35%"],
            center=["80%", "82%"],
            itemstyle_opts=opts.ItemStyleOpts(
                border_width=1, border_color="rgba(0,0,0,0.3)"
            ),
        )
        .set_global_opts(
            tooltip_opts=opts.TooltipOpts(is_show=True, formatter="{b} {d}%"),
            legend_opts=opts.LegendOpts(is_show=False),
        )
    )
    
    return pie

生成pie测试:

pie = get_year_chart_pie(year=year,map_data=map_data,min_data=min_data,max_data=max_data)
pie.render_notebook()

在这里插入图片描述

生成2013年网格组合图

定义生成网格图函数get_year_chart:

def get_year_chart(year: str,data,min_data=0,max_data=1000):
    # data为每个年份的各个省份GDP数据    
    map_data = [
        [[x["name"], x["value"]] for x in d["data"]] for d in data if d["time"] == year
    ][0]
    # print(map_data) #当输入的年份为2013时
    '''
    [['广东省', [62475.0, 9.85, '广东省']], ['江苏省', [59753.0, 9.42, '江苏省']], ['山东省', [55230.0, 8.71, '山东省']], 
    ...
    ['青海省', [2122.0, 0.33, '青海省']], ['西藏自治区', [816.0, 0.13, '西藏自治区']]]
    '''
    min_data, max_data = (minNum, maxNum)
    data_mark: List = []
    i = 0
    for x in time_list:
        if x == year:
            data_mark.append(total_num[i])
        else:
            data_mark.append("")
        i = i + 1
    # print("data_mark-->",data_mark)
    # data_mark--> [63.4, '', '', '', '', ''] #当输入的年份为2013时
    
    map_chart = get_year_chart_map(year=year,map_data=map_data,min_data=min_data,max_data=max_data)

    line = get_year_chart_line(year=year,map_data=map_data,min_data=min_data,max_data=max_data,data_mark=data_mark)

    bar = get_year_chart_bar(year=year,map_data=map_data,min_data=min_data,max_data=max_data)

    pie = get_year_chart_pie(year=year,map_data=map_data,min_data=min_data,max_data=max_data)

    grid_chart = (
        Grid()
        .add(
            bar,
            grid_opts=opts.GridOpts(
                pos_left="10", pos_right="45%", pos_top="50%", pos_bottom="5"
            ),
        )
        .add(
            line,
            grid_opts=opts.GridOpts(
                pos_left="65%", pos_right="80", pos_top="10%", pos_bottom="50%"
            ),
        )
        .add(pie, grid_opts=opts.GridOpts(pos_left="45%", pos_top="60%"))
        .add(map_chart, grid_opts=opts.GridOpts())
    )

    return grid_chart

测试网格图:

g = get_year_chart(year='2013年',data=data)
g.render_notebook()
# g.render("g.html")

在这里插入图片描述

生成包含timeline的网格组合图

if __name__ == "__main__":
    timeline = Timeline(
        init_opts=opts.InitOpts(width="1600px", height="900px", theme=ThemeType.DARK)
    )
    for y in time_list:
        g = get_year_chart(year=y,data=data)
        timeline.add(g, time_point=str(y))

    timeline.add_schema(
        orient="vertical",
        is_auto_play=True,
        is_inverse=True,
        play_interval=5000,
        pos_left="null",
        pos_right="5",
        pos_top="20",
        pos_bottom="20",
        width="60",
        label_opts=opts.LabelOpts(is_show=True, color="#fff"),
    )
#     timeline.render_notebook()

    timeline.render("china_gdp_from_2013_to_2018.html")

查看china_gdp_from_1993_to_2018.html,结果如下:
在这里插入图片描述

完整代码如下:

from typing import List

import pyecharts.options as opts
from pyecharts.globals import ThemeType
from pyecharts.commons.utils import JsCode
from pyecharts.charts import Timeline, Grid, Bar, Map, Pie, Line

"""
Gallery 使用 pyecharts 1.3.0
From pyecharts 交流分享群 -- 郭昱
"""
data = [
    {
        "time": "2013年",
        "data": [
            {"name": "广东省", "value": [62475.0, 9.85, "广东省"]},
            {"name": "江苏省", "value": [59753.0, 9.42, "江苏省"]},
            {"name": "山东省", "value": [55230.0, 8.71, "山东省"]},
            {"name": "浙江省", "value": [37757.0, 5.95, "浙江省"]},
            {"name": "河南省", "value": [32191.0, 5.07, "河南省"]},
            {"name": "河北省", "value": [28443.0, 4.48, "河北省"]},
            {"name": "辽宁省", "value": [27213.0, 4.29, "辽宁省"]},
            {"name": "四川省", "value": [26392.0, 4.16, "四川省"]},
            {"name": "湖北省", "value": [24792.0, 3.91, "湖北省"]},
            {"name": "湖南省", "value": [24622.0, 3.88, "湖南省"]},
            {"name": "福建省", "value": [21868.0, 3.45, "福建省"]},
            {"name": "上海市", "value": [21818.0, 3.44, "上海市"]},
            {"name": "北京市", "value": [19801.0, 3.12, "北京市"]},
            {"name": "安徽省", "value": [19229.0, 3.03, "安徽省"]},
            {"name": "内蒙古", "value": [16917.0, 2.67, "内蒙古"]},
            {"name": "陕西省", "value": [16205.0, 2.55, "陕西省"]},
            {"name": "黑龙江省", "value": [14455.0, 2.28, "黑龙江省"]},
            {"name": "广西壮族自治区", "value": [14450.0, 2.28, "广西壮族自治区"]},
            {"name": "天津市", "value": [14442.0, 2.28, "天津市"]},
            {"name": "江西省", "value": [14410.0, 2.27, "江西省"]},
            {"name": "吉林省", "value": [13046.0, 2.06, "吉林省"]},
            {"name": "重庆市", "value": [12783.0, 2.02, "重庆市"]},
            {"name": "山西省", "value": [12665.0, 2.0, "山西省"]},
            {"name": "云南省", "value": [11832.0, 1.87, "云南省"]},
            {"name": "新疆维吾尔自治区", "value": [8444.0, 1.33, "新疆维吾尔自治区"]},
            {"name": "贵州省", "value": [8087.0, 1.27, "贵州省"]},
            {"name": "甘肃省", "value": [6331.0, 1.0, "甘肃省"]},
            {"name": "海南省", "value": [3178.0, 0.5, "海南省"]},
            {"name": "宁夏回族自治区", "value": [2578.0, 0.41, "宁夏回族自治区"]},
            {"name": "青海省", "value": [2122.0, 0.33, "青海省"]},
            {"name": "西藏自治区", "value": [816.0, 0.13, "西藏自治区"]},
        ],
    },
    {
        "time": "2014年",
        "data": [
            {"name": "广东省", "value": [67810.0, 9.91, "广东省"]},
            {"name": "江苏省", "value": [65088.0, 9.51, "江苏省"]},
            {"name": "山东省", "value": [59427.0, 8.68, "山东省"]},
            {"name": "浙江省", "value": [40173.0, 5.87, "浙江省"]},
            {"name": "河南省", "value": [34938.0, 5.11, "河南省"]},
            {"name": "河北省", "value": [29421.0, 4.3, "河北省"]},
            {"name": "辽宁省", "value": [28627.0, 4.18, "辽宁省"]},
            {"name": "四川省", "value": [28537.0, 4.17, "四川省"]},
            {"name": "湖北省", "value": [27379.0, 4.0, "湖北省"]},
            {"name": "湖南省", "value": [27037.0, 3.95, "湖南省"]},
            {"name": "福建省", "value": [24056.0, 3.52, "福建省"]},
            {"name": "上海市", "value": [23568.0, 3.44, "上海市"]},
            {"name": "北京市", "value": [21331.0, 3.12, "北京市"]},
            {"name": "安徽省", "value": [20849.0, 3.05, "安徽省"]},
            {"name": "内蒙古", "value": [17770.0, 2.6, "内蒙古"]},
            {"name": "陕西省", "value": [17690.0, 2.58, "陕西省"]},
            {"name": "天津市", "value": [15727.0, 2.3, "天津市"]},
            {"name": "江西省", "value": [15715.0, 2.3, "江西省"]},
            {"name": "广西壮族自治区", "value": [15673.0, 2.29, "广西壮族自治区"]},
            {"name": "黑龙江省", "value": [15039.0, 2.2, "黑龙江省"]},
            {"name": "重庆市", "value": [14263.0, 2.08, "重庆市"]},
            {"name": "吉林省", "value": [13803.0, 2.02, "吉林省"]},
            {"name": "云南省", "value": [12815.0, 1.87, "云南省"]},
            {"name": "山西省", "value": [12761.0, 1.86, "山西省"]},
            {"name": "新疆维吾尔自治区", "value": [9273.0, 1.36, "新疆维吾尔自治区"]},
            {"name": "贵州省", "value": [9266.0, 1.35, "贵州省"]},
            {"name": "甘肃省", "value": [6837.0, 1.0, "甘肃省"]},
            {"name": "海南省", "value": [3501.0, 0.51, "海南省"]},
            {"name": "宁夏回族自治区", "value": [2752.0, 0.4, "宁夏回族自治区"]},
            {"name": "青海省", "value": [2303.0, 0.34, "青海省"]},
            {"name": "西藏自治区", "value": [921.0, 0.13, "西藏自治区"]},
        ],
    },
    {
        "time": "2015年",
        "data": [
            {"name": "广东省", "value": [72813.0, 10.07, "广东省"]},
            {"name": "江苏省", "value": [70116.0, 9.7, "江苏省"]},
            {"name": "山东省", "value": [63002.0, 8.72, "山东省"]},
            {"name": "浙江省", "value": [42886.0, 5.93, "浙江省"]},
            {"name": "河南省", "value": [37002.0, 5.12, "河南省"]},
            {"name": "四川省", "value": [30053.0, 4.16, "四川省"]},
            {"name": "河北省", "value": [29806.0, 4.12, "河北省"]},
            {"name": "湖北省", "value": [29550.0, 4.09, "湖北省"]},
            {"name": "湖南省", "value": [28902.0, 4.0, "湖南省"]},
            {"name": "辽宁省", "value": [28669.0, 3.97, "辽宁省"]},
            {"name": "福建省", "value": [25980.0, 3.59, "福建省"]},
            {"name": "上海市", "value": [25123.0, 3.48, "上海市"]},
            {"name": "北京市", "value": [23015.0, 3.18, "北京市"]},
            {"name": "安徽省", "value": [22006.0, 3.04, "安徽省"]},
            {"name": "陕西省", "value": [18022.0, 2.49, "陕西省"]},
            {"name": "内蒙古", "value": [17832.0, 2.47, "内蒙古"]},
            {"name": "广西壮族自治区", "value": [16803.0, 2.32, "广西壮族自治区"]},
            {"name": "江西省", "value": [16724.0, 2.31, "江西省"]},
            {"name": "天津市", "value": [16538.0, 2.29, "天津市"]},
            {"name": "重庆市", "value": [15717.0, 2.17, "重庆市"]},
            {"name": "黑龙江省", "value": [15084.0, 2.09, "黑龙江省"]},
            {"name": "吉林省", "value": [14063.0, 1.95, "吉林省"]},
            {"name": "云南省", "value": [13619.0, 1.88, "云南省"]},
            {"name": "山西省", "value": [12766.0, 1.77, "山西省"]},
            {"name": "贵州省", "value": [10503.0, 1.45, "贵州省"]},
            {"name": "新疆维吾尔自治区", "value": [9325.0, 1.29, "新疆维吾尔自治区"]},
            {"name": "甘肃省", "value": [6790.0, 0.94, "甘肃省"]},
            {"name": "海南省", "value": [3703.0, 0.51, "海南省"]},
            {"name": "宁夏回族自治区", "value": [2912.0, 0.4, "宁夏回族自治区"]},
            {"name": "青海省", "value": [2417.0, 0.33, "青海省"]},
            {"name": "西藏自治区", "value": [1026.0, 0.14, "西藏自治区"]},
        ],
    },
    {
        "time": "2016年",
        "data": [
            {"name": "广东省", "value": [80855.0, 10.37, "广东省"]},
            {"name": "江苏省", "value": [77388.0, 9.92, "江苏省"]},
            {"name": "山东省", "value": [68024.0, 8.72, "山东省"]},
            {"name": "浙江省", "value": [47251.0, 6.06, "浙江省"]},
            {"name": "河南省", "value": [40472.0, 5.19, "河南省"]},
            {"name": "四川省", "value": [32935.0, 4.22, "四川省"]},
            {"name": "湖北省", "value": [32665.0, 4.19, "湖北省"]},
            {"name": "河北省", "value": [32070.0, 4.11, "河北省"]},
            {"name": "湖南省", "value": [31551.0, 4.04, "湖南省"]},
            {"name": "福建省", "value": [28811.0, 3.69, "福建省"]},
            {"name": "上海市", "value": [28179.0, 3.61, "上海市"]},
            {"name": "北京市", "value": [25669.0, 3.29, "北京市"]},
            {"name": "安徽省", "value": [24408.0, 3.13, "安徽省"]},
            {"name": "辽宁省", "value": [22247.0, 2.85, "辽宁省"]},
            {"name": "陕西省", "value": [19400.0, 2.49, "陕西省"]},
            {"name": "江西省", "value": [18499.0, 2.37, "江西省"]},
            {"name": "广西壮族自治区", "value": [18318.0, 2.35, "广西壮族自治区"]},
            {"name": "内蒙古", "value": [18128.0, 2.32, "内蒙古"]},
            {"name": "天津市", "value": [17885.0, 2.29, "天津市"]},
            {"name": "重庆市", "value": [17741.0, 2.27, "重庆市"]},
            {"name": "黑龙江省", "value": [15386.0, 1.97, "黑龙江省"]},
            {"name": "云南省", "value": [14788.0, 1.9, "云南省"]},
            {"name": "吉林省", "value": [14777.0, 1.89, "吉林省"]},
            {"name": "山西省", "value": [13050.0, 1.67, "山西省"]},
            {"name": "贵州省", "value": [11777.0, 1.51, "贵州省"]},
            {"name": "新疆维吾尔自治区", "value": [9650.0, 1.24, "新疆维吾尔自治区"]},
            {"name": "甘肃省", "value": [7200.0, 0.92, "甘肃省"]},
            {"name": "海南省", "value": [4053.0, 0.52, "海南省"]},
            {"name": "宁夏回族自治区", "value": [3169.0, 0.41, "宁夏回族自治区"]},
            {"name": "青海省", "value": [2572.0, 0.33, "青海省"]},
            {"name": "西藏自治区", "value": [1151.0, 0.15, "西藏自治区"]},
        ],
    },
    {
        "time": "2017年",
        "data": [
            {"name": "广东省", "value": [89705.0, 10.59, "广东省"]},
            {"name": "江苏省", "value": [85870.0, 10.14, "江苏省"]},
            {"name": "山东省", "value": [72634.0, 8.57, "山东省"]},
            {"name": "浙江省", "value": [51768.0, 6.11, "浙江省"]},
            {"name": "河南省", "value": [44553.0, 5.26, "河南省"]},
            {"name": "四川省", "value": [36980.0, 4.37, "四川省"]},
            {"name": "湖北省", "value": [35478.0, 4.19, "湖北省"]},
            {"name": "河北省", "value": [34016.0, 4.02, "河北省"]},
            {"name": "湖南省", "value": [33903.0, 4.0, "湖南省"]},
            {"name": "福建省", "value": [32182.0, 3.8, "福建省"]},
            {"name": "上海市", "value": [30633.0, 3.62, "上海市"]},
            {"name": "北京市", "value": [28015.0, 3.31, "北京市"]},
            {"name": "安徽省", "value": [27018.0, 3.19, "安徽省"]},
            {"name": "辽宁省", "value": [23409.0, 2.76, "辽宁省"]},
            {"name": "陕西省", "value": [21899.0, 2.59, "陕西省"]},
            {"name": "江西省", "value": [20006.0, 2.36, "江西省"]},
            {"name": "重庆市", "value": [19425.0, 2.29, "重庆市"]},
            {"name": "天津市", "value": [18549.0, 2.19, "天津市"]},
            {"name": "广西壮族自治区", "value": [18523.0, 2.19, "广西壮族自治区"]},
            {"name": "云南省", "value": [16376.0, 1.93, "云南省"]},
            {"name": "内蒙古", "value": [16096.0, 1.9, "内蒙古"]},
            {"name": "黑龙江省", "value": [15903.0, 1.88, "黑龙江省"]},
            {"name": "山西省", "value": [15528.0, 1.83, "山西省"]},
            {"name": "吉林省", "value": [14945.0, 1.76, "吉林省"]},
            {"name": "贵州省", "value": [13541.0, 1.6, "贵州省"]},
            {"name": "新疆维吾尔自治区", "value": [10882.0, 1.28, "新疆维吾尔自治区"]},
            {"name": "甘肃省", "value": [7460.0, 0.88, "甘肃省"]},
            {"name": "海南省", "value": [4463.0, 0.53, "海南省"]},
            {"name": "宁夏回族自治区", "value": [3444.0, 0.41, "宁夏回族自治区"]},
            {"name": "青海省", "value": [2625.0, 0.31, "青海省"]},
            {"name": "西藏自治区", "value": [1311.0, 0.15, "西藏自治区"]},
        ],
    },
    {
        "time": "2018年",
        "data": [
            {"name": "广东省", "value": [97278.0, 10.63, "广东省"]},
            {"name": "江苏省", "value": [92595.0, 10.12, "江苏省"]},
            {"name": "山东省", "value": [76470.0, 8.36, "山东省"]},
            {"name": "浙江省", "value": [56197.0, 6.14, "浙江省"]},
            {"name": "河南省", "value": [48056.0, 5.25, "河南省"]},
            {"name": "四川省", "value": [40678.0, 4.45, "四川省"]},
            {"name": "湖北省", "value": [39367.0, 4.3, "湖北省"]},
            {"name": "湖南省", "value": [36426.0, 3.98, "湖南省"]},
            {"name": "河北省", "value": [36010.0, 3.94, "河北省"]},
            {"name": "福建省", "value": [35804.0, 3.91, "福建省"]},
            {"name": "上海市", "value": [32680.0, 3.57, "上海市"]},
            {"name": "北京市", "value": [30320.0, 3.31, "北京市"]},
            {"name": "安徽省", "value": [30007.0, 3.28, "安徽省"]},
            {"name": "辽宁省", "value": [25315.0, 2.77, "辽宁省"]},
            {"name": "陕西省", "value": [24438.0, 2.67, "陕西省"]},
            {"name": "江西省", "value": [21985.0, 2.4, "江西省"]},
            {"name": "重庆市", "value": [20363.0, 2.23, "重庆市"]},
            {"name": "广西壮族自治区", "value": [20353.0, 2.23, "广西壮族自治区"]},
            {"name": "天津市", "value": [18810.0, 2.06, "天津市"]},
            {"name": "云南省", "value": [17881.0, 1.95, "云南省"]},
            {"name": "内蒙古", "value": [17289.0, 1.89, "内蒙古"]},
            {"name": "山西省", "value": [16818.0, 1.84, "山西省"]},
            {"name": "黑龙江省", "value": [16362.0, 1.79, "黑龙江省"]},
            {"name": "吉林省", "value": [15075.0, 1.65, "吉林省"]},
            {"name": "贵州省", "value": [14806.0, 1.62, "贵州省"]},
            {"name": "新疆维吾尔自治区", "value": [12199.0, 1.33, "新疆维吾尔自治区"]},
            {"name": "甘肃省", "value": [8246.0, 0.9, "甘肃省"]},
            {"name": "海南省", "value": [4832.0, 0.53, "海南省"]},
            {"name": "宁夏回族自治区", "value": [3705.0, 0.41, "宁夏回族自治区"]},
            {"name": "青海省", "value": [2865.0, 0.31, "青海省"]},
            {"name": "西藏自治区", "value": [1478.0, 0.16, "西藏自治区"]},
        ],
    },
]

# 生成2013-2019年的时间列表
time_list = [str(d) + "年" for d in range(2013, 2019)] 
time_list

total_num = [
    63.4,
    68.4,
    72.3,
    78,
    84.7,
    91.5,
]
total_num


maxNum = 97300
minNum = 30


#  生成地图 
def get_year_chart_map(year: str,map_data,min_data=0,max_data=1000):
    map_chart = (
        Map()
        .add(
            series_name="",
            data_pair=map_data,
            maptype='china',
            zoom=1,
            center=[119.5, 34.5],
            is_map_symbol_show=False,
            itemstyle_opts={
                "normal": {"areaColor": "#323c48", "borderColor": "#404a59"},
                "emphasis": {
                    "label": {"show": Timeline},
                    "areaColor": "rgba(255,255,255, 0.5)",
                },
            },
        )
        .set_global_opts(
            title_opts=opts.TitleOpts(
                title="" + str(year) + "全国分地区GPD情况(单位:亿) 数据来源:国家统计局",
                subtitle="",
                pos_left="center",
                pos_top="top",
                title_textstyle_opts=opts.TextStyleOpts(
                    font_size=25, color="rgba(255,255,255, 0.9)"
                ),
            ),
            tooltip_opts=opts.TooltipOpts(
                is_show=True,
                formatter=JsCode(
                    """function(params) {
                    if ('value' in params.data) {
                        return params.data.value[2] + ': ' + params.data.value[0];
                    }
                }"""
                ),
            ),
            visualmap_opts=opts.VisualMapOpts(
                is_calculable=True,
                dimension=0,
                pos_left="30",
                pos_top="center",
                range_text=["High", "Low"],
                range_color=["lightskyblue", "yellow", "orangered"],
                textstyle_opts=opts.TextStyleOpts(color="#ddd"),
                min_=min_data,
                max_=max_data,
            ),
        )
    )
    return map_chart
        
def get_year_chart_line(year=year,map_data=map_data,min_data=min_data,max_data=max_data,data_mark=data_mark):
    line_chart = (
        Line()
        .add_xaxis(time_list)
        .add_yaxis('', total_num)
        .add_yaxis(
            "",
            data_mark,
            markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(type_="max")]),
        )
        .set_series_opts(label_opts=opts.LabelOpts(is_show=False))
        .set_global_opts(
            title_opts=opts.TitleOpts(
                title="全国GDP总量{}(单位:万亿)".format(year), pos_left="50%", pos_top="5%"
            )
        )
    )
    return line_chart

def get_year_chart_bar(year=year,map_data=map_data,min_data=min_data,max_data=max_data):
    bar_x_data = [x[0] for x in map_data]
    bar_y_data = [{"name": x[0], "value": x[1][0]} for x in map_data]
    bar = (
        Bar()
        .add_xaxis(xaxis_data=bar_x_data)
        .add_yaxis(
            series_name="",
            y_axis=bar_y_data,
            label_opts=opts.LabelOpts(
                is_show=True, position="right", formatter="{b} : {c}"
            ),
        )
        .reversal_axis()
        .set_global_opts(
            xaxis_opts=opts.AxisOpts(
                max_=maxNum, axislabel_opts=opts.LabelOpts(is_show=False)
            ),
            yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(is_show=False)),
            tooltip_opts=opts.TooltipOpts(is_show=False),
            visualmap_opts=opts.VisualMapOpts(
                is_calculable=True,
                dimension=0,
                pos_left="10",
                pos_top="top",
                range_text=["High", "Low"],
                range_color=["lightskyblue", "yellow", "orangered"],
                textstyle_opts=opts.TextStyleOpts(color="#ddd"),
                min_=min_data,
                max_=max_data,
            ),
        )
    )
    
    return bar

def get_year_chart_pie(year=year,map_data=map_data,min_data=min_data,max_data=max_data):
    pie_data = [[x[0], x[1][0]] for x in map_data]
    pie = (
        Pie()
        .add(
            series_name="",
            data_pair=pie_data,
            radius=["15%", "35%"],
            center=["80%", "82%"],
            itemstyle_opts=opts.ItemStyleOpts(
                border_width=1, border_color="rgba(0,0,0,0.3)"
            ),
        )
        .set_global_opts(
            tooltip_opts=opts.TooltipOpts(is_show=True, formatter="{b} {d}%"),
            legend_opts=opts.LegendOpts(is_show=False),
        )
    )
    
    return pie

def get_year_chart(year: str,data,min_data=0,max_data=1000):
    # data为每个年份的各个省份GDP数据    
    map_data = [
        [[x["name"], x["value"]] for x in d["data"]] for d in data if d["time"] == year
    ][0]
    # print(map_data) #当输入的年份为2013时
    '''
    [['广东省', [62475.0, 9.85, '广东省']], ['江苏省', [59753.0, 9.42, '江苏省']], ['山东省', [55230.0, 8.71, '山东省']], 
    ...
    ['青海省', [2122.0, 0.33, '青海省']], ['西藏自治区', [816.0, 0.13, '西藏自治区']]]
    '''
    min_data, max_data = (minNum, maxNum)
    data_mark: List = []
    i = 0
    for x in time_list:
        if x == year:
            data_mark.append(total_num[i])
        else:
            data_mark.append("")
        i = i + 1
    # print("data_mark-->",data_mark)
    # data_mark--> [63.4, '', '', '', '', ''] #当输入的年份为2013时
    
    map_chart = get_year_chart_map(year=year,map_data=map_data,min_data=min_data,max_data=max_data)

    line = get_year_chart_line(year=year,map_data=map_data,min_data=min_data,max_data=max_data,data_mark=data_mark)

    bar = get_year_chart_bar(year=year,map_data=map_data,min_data=min_data,max_data=max_data)

    pie = get_year_chart_pie(year=year,map_data=map_data,min_data=min_data,max_data=max_data)

    grid_chart = (
        Grid()
        .add(
            bar,
            grid_opts=opts.GridOpts(
                pos_left="10", pos_right="45%", pos_top="50%", pos_bottom="5"
            ),
        )
        .add(
            line,
            grid_opts=opts.GridOpts(
                pos_left="65%", pos_right="80", pos_top="10%", pos_bottom="50%"
            ),
        )
        .add(pie, grid_opts=opts.GridOpts(pos_left="45%", pos_top="60%"))
        .add(map_chart, grid_opts=opts.GridOpts())
    )

    return grid_chart

if __name__ == "__main__":
    timeline = Timeline(
        init_opts=opts.InitOpts(width="1600px", height="900px", theme=ThemeType.DARK)
    )
    for y in time_list:
        g = get_year_chart(year=y,data=data)
        timeline.add(g, time_point=str(y))

    timeline.add_schema(
        orient="vertical",
        is_auto_play=True,
        is_inverse=True,
        play_interval=5000,
        pos_left="null",
        pos_right="5",
        pos_top="20",
        pos_bottom="20",
        width="60",
        label_opts=opts.LabelOpts(is_show=True, color="#fff"),
    )
#     timeline.render_notebook()

    timeline.render("china_gdp_from_201313_to_2018.html")

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/443803.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

图片加水印的简单方法

图片加水印的简单方法~许多小伙伴都习惯在需要对外发布的图片上添加水印,添加水印后就不必担心图片被盗用或被用于其它不良目的,给我们造成不好的影响。然而,许多用户不知道如何为图片添加水印,也不知道应该选择哪种软件来进行操作…

C/C++|物联网开发入门+项目实战|空间读写|非字符空间|返回值内部实现|嵌入式C语言高级|C语言函数的使用(2)-学习笔记(12)

文章目录 空间的读写作用实现strlen实现strcpy 非字符空间void* 返回值返回连续空间类型示例: 函数内部实现示例: 参考: 麦子学院-嵌入式C语言高级-C语言函数的使用 空间的读写 void fun(char *p); const char *p 只读空间,只为…

多功能PDF工具合集:PDF Squeezer - PDF Toolbox Mac

PDF Squeezer - PDF Toolbox Mac是多功能PDF工具合集。专为操作 PDF 文件而设计,包含几乎所有你能想象到的操作,例如:压缩、合并、拆分、提取、插入、提取图像、转换图像、提取文本、排序、加密等。如果你正在为操作PDF文件发愁,快…

关于yolov8的一些理解

文章目录 1.前言2.创新点及工作3. 网络结构3.1 BackBone3.1.1 C2F3.1.2 结构微调3.1.2 SPPF 3.2 Neck3.3 Head 4.正样本匹配策略4.1 静态分配策略&动态分配策略4.2 TaskAlignedAssigner 5.损失函数5.1 概述5.2 Distribution Focal Loss 6.总结 1.前言 YOLOv8 是 ultralyti…

在Eclipse中安装配置JDK11

下载安装包 从请官方下载,地址为:https://www.oracle.com/java/technologies/javase-jdk11-downloads.html,选择相应的版本下载即可。注意,现在需要注册才能下载。 ** ** 安装JDK11 使用下载的安装包进行安装,双击可…

Hyperledger Fabric 2.x 环境搭建

一、说明 区块链网络的核心是分布式账本,在这个账本中记录了网络中发生的所有交易信息。 Hyperledger Fabric 是一个是开源的,企业级的,带权限的分布式账本解决方案的平台。Hyperledger Fabric 由模块化架构支撑,并具备极佳的保…

拉格朗日粒子扩散模式FLEXPART

为了高效、精准地治理区域大气污染,需要弄清污染物的来源。拉格朗日粒子扩散模式FLEXPART通过计算点、线、面或体积源释放的大量粒子的轨迹,来描述示踪物在大气中长距离、中尺度的传输、扩散、干湿沉降和辐射衰减等过程。该模式既可以通过时间的前向运算…

Pytorch基础 - 7. torch.transpose() 和 torch.permute()

目录 1. torch.transpose(dim0, dim1) 2. torch.permute(dims) 3. 在转置函数之后使用view() PyTorch中使用torch.transpose() 和 torch.permute()可对张量进行维度的转置,具体内容如下: 1. torch.transpose(dim0, dim1) 参数: 需要转置的两个维度…

React native RN 开发实例

多入口加载方式 React Native 混合开发多入口加载方式 - 知乎 initialProperties 官方文档:React Navigation moduleName 案例:GitHub - hcn1519/ReactNative-iOS-Example React Native 混合开发多入口加载方式 - 知乎 项目结构 参考&#xff1…

传奇修改怪物属性教程:传奇服务端架设后怪物不主动攻击是什么原因?

当你架设好传奇服务端后怪物不主动攻击是什么原因呢?今天飞飞来和你分享 1、检查是否进入了管理员隐藏模式 如果是你设置了GM号进入了隐身模式,登录游戏就会有登录脚本默认管理上线检测,怪物看到你是GM管理员自然不会攻击你的,你…

(顶级理解)为什么Vue中的v-if 和v-for不建议一起用?

目录 1.背景 2.原因 3.通俗案例 4.解决方案 5.扩展(强烈看下) 1.背景 我们都知道v-if和v-for是vue开发工程中十分常用的方法 2.原因 当 v-if 与 v-for 一起使用时,v-for 具有比 v-if 更高的优先级。这意味着 v-if 将分别重复运行于 每…

jQuery 基础入门速成下篇

jQuery高级 事件冒泡 什么是事件冒泡? 在一个对象上触发某类事件,此对象上定义了此事件的处理程序,那么此事件就会调用这个处理程序,如果没有定义此事件处理程序或事件返回true,那么这个事件会向这个对象的父级对象传…

门禁系统中人脸检测技术的原理剖析和使用教程

引言 人脸检测 API 是一种基于深度学习技术的图像处理API,可以快速地检测出一张图片中的人脸,并返回人脸的位置和关键点坐标,在人脸识别系统、人脸情绪识别等多种场景下都有极大的应用。 本文将从人脸检测的发展历程、原理、特点等角度出发…

第五章 RNN

目录 5.1 概率和语言模型5.1.1 概率视角下的 word2vec5.1.2 语言模型5.1.3 将CBOW模型用作语言模型? 5.2 RNN5.2.1 循环的神经网络5.2.2 展开循环5.2.3 Backpropagation Through Time5.2.4 Truncated BPTT5.2.5 Truncated BPTT的mini-batch学习 5.3 RNN的实现5.3.1 …

【博云+智领云】携手云原生大数据领域,开展深度合作

近日,博云与LinkTimeCloud智领云达成战略合作伙伴关系,基于此前坚实合作基础,全面拓宽合作广度与深度,共同推出基于Kubernetes的企业级容器云云原生大数据技术融合的新型数字化IT底座,并且在某国家级创新中心首次落地。…

高精度的乘除法(C++实现)

前言:我们都熟知高精度的加减法可以用字符串来模拟实现,其实乘除法的高精度计算也和加减法类似却也略有不同,下面我们一起来看一下高精度的乘除法的模拟实现,希望可以帮助到大家。 目录 1.高精度乘法的实现 1.1原理重点难点解析…

一图看懂 pyexcel 模块:提供统一 API用来读写操作 Excel 文件的库, 资料整理+笔记(大全)

本文由 大侠(AhcaoZhu)原创,转载请声明。 链接: https://blog.csdn.net/Ahcao2008 一图看懂 pyexcel 模块:提供统一 API用来读写操作 Excel 文件的库, 资料整理笔记(大全) 摘要模块图类关系图模块全展开【pyexcel】统计常量模块1 …

ABAP:自定义搜索帮助:可参考标准函数F4IF_SHLP_EXIT_EXAMPLE

当我们在自定义选择屏幕中, 需要写入我们自定义的搜索帮助的时候,可以通过预定义函数来实现: 实例说明: 第一步:创建搜索帮助SE11分销渠道(Z_VTWEG) 1.选择基本索引帮助: 2.选择参考表,因为这…

Java 基础——HashMap 底层数据结构与源码分析

目录 1.HashMap 简介2.HashMap 底层数据结构2.2.JDK1.8 之前2.3.JDK1.8 及以后 3.常量定义3.1.默认初始化容量3.2.最大容量3.3.负载因子3.4.阈值 4.HashMap 源码分析4.1.构造函数4.2.Node<K, V>4.2.put(K key, V value)流程源码 4.3.get(Object key)流程源码 4.4.resize(…

java使用阿里云oss上传文件

java使用阿里云oss上传文件 1、oss 是什么&#xff1f; OSS是阿里云对象存储服务&#xff08;Object Storage Service&#xff09;的一个简称&#xff0c;它是阿里云提供的海量、安全、低成本、高可靠的云存储服务。 即开即用、无限大空间的存储集群。相较传统建服务器存储而…