Python-Pyecharts画动态图(时间+静态图)[五]

动态图是把一个个静态图根据一定的数据(时间)串联起来,在把他以“视频”的格式在html上展示;
就如下图所示,图形是一个根据时间来进行循环展示的,有时间轴!
在这里插入图片描述

动态桑葚图
from pyecharts import options as opts
from pyecharts.charts import Sankey, Timeline
from pyecharts.faker import Faker
 
tl = Timeline()
names = ("商家A", "商家B", "商家C",'商家D','商家E','商家F')
nodes = [{"name": name} for name in names]
for i in range(2015, 2020):
    links = [
        {"source": names[0], "target": names[1], "value": Faker.values()[0],"color":"yellow"},
        {"source": names[1], "target": names[2], "value": Faker.values()[0]},
        {"source": names[1], "target": names[5], "value": Faker.values()[0]},
        {"source": names[3], "target": names[1], "value": Faker.values()[0]},
        {"source": names[1], "target": names[2], "value": Faker.values()[0]},
        {"source": names[1], "target": names[5], "value": Faker.values()[0]},
        {"source": names[3], "target": names[4], "value": Faker.values()[0]},
        {"source": names[4], "target": names[2], "value": Faker.values()[0]},
        {"source": names[4], "target": names[5], "value": Faker.values()[0]},
    ]

    sankey = (
        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="{}年商店(A, B, C)营业额差".format(i))
        )
    )
    tl.add(sankey, "{}年".format(i))
tl.render("G:/HTML图/桑葚图.html")   

Python-Pyecharts画动态图(时间+静态图)[五]_第1张图片

动态地图

from pyecharts import options as opts
from pyecharts.charts import Map, Timeline
from pyecharts.render import make_snapshot
from snapshot_selenium import snapshot
tl = Timeline()

data1 = [
    ('湖北', 1000), ('浙江', 661), ('广东', 632), ('河南', 493), ('湖南', 999),
    ('安徽', 340), ('江西', 333), ('重庆', 275), ('江苏', 236), ('四川', 231),
    ('山东', 55), ('北京', 191), ('上海', 182), ('福建', 1000), ('陕西', 116),
    ('广西', 111), ('云南', 105), ('河北', 104), ('黑龙江', 95), ('辽宁', 69),
    ('海南', 64), ('新疆', 21), ('内蒙古', 21), ('宁夏', 28), ('青海', 11), ('甘肃', 40), ('西藏', 1),
    ('贵州', 38), ('山西', 0), ('吉林', 23), ('台湾', 10), ('天津', 48), ('香港', 14), ('澳门', 8)
]
data2 = [
    ('湖北', 5000), ('浙江', 661), ('广东', 632), ('河南', 493), ('湖南', 463),
    ('安徽', 340), ('江西', 333), ('重庆', 275), ('江苏', 236), ('四川', 231),
    ('山东', 230), ('北京', 191), ('上海', 555), ('福建', 159), ('陕西', 116),
    ('广西', 111), ('云南', 500), ('河北', 104), ('黑龙江', 788), ('辽宁', 69),
    ('海南', 64), ('新疆', 21), ('内蒙古', 21), ('宁夏', 28), ('青海', 11), ('甘肃', 40), ('西藏', 1),
    ('贵州', 38), ('山西', 56), ('吉林', 23), ('台湾', 10), ('天津', 48), ('香港', 14), ('澳门', 8)
]
data3 = [
    ('湖北', 100000), ('浙江', 661), ('广东', 632), ('河南', 493), ('湖南', 888),
    ('安徽', 340), ('江西', 333), ('重庆', 275), ('江苏', 236), ('四川', 231),
    ('山东', 230), ('北京', 444), ('上海', 22), ('福建', 159), ('陕西', 116),
    ('广西', 111), ('云南', 105), ('河北', 104), ('黑龙江', 95), ('辽宁', 888),
    ('海南', 64), ('新疆', 21), ('内蒙古', 21), ('宁夏', 28), ('青海', 11), ('甘肃', 40), ('西藏', 1),
    ('贵州', 0), ('山西', 56), ('吉林', 23), ('台湾', 10), ('天津', 48), ('香港', 14), ('澳门', 8)
]
data4 = [
    ('湖北', 500), ('浙江', 661), ('广东', 222), ('河南', 493), ('湖南', 463),
    ('安徽', 340), ('江西', 333), ('重庆', 275), ('江苏', 236), ('四川', 231),
    ('山东', 230), ('北京', 191), ('上海', 182), ('福建', 159), ('陕西', 116),
    ('广西', 111), ('云南', 105), ('河北', 104), ('黑龙江', 95), ('辽宁', 69),
    ('海南', 64), ('新疆', 21), ('内蒙古', 21), ('宁夏', 28), ('青海', 11), ('甘肃', 40), ('西藏', 1),
    ('贵州', 38), ('山西', 56), ('吉林', 23), ('台湾', 10), ('天津', 48), ('香港', 14), ('澳门', 8)
]
for i,j in zip(range(1999, 2003),[data1,data2,data3,data4]):

    c = Map(init_opts=opts.InitOpts(bg_color = "white"))#设置地图颜色


    c.add(series_name="疫情地图", data_pair=j, maptype="china")#地图名称


    c.set_global_opts(
        title_opts=opts.TitleOpts(title="疫情地图范例"),
        visualmap_opts=opts.VisualMapOpts(
            max_=9500,
            is_piecewise=True,
            pieces=[{"max": 30, "min": 0, "label": "0-9", "color": "#D9ECF2"},
                    {"max": 199, "min": 10, "label": "10-99",
                     "color": "#D1DCE2"},
                    {"max": 499, "min": 100, "label": "100-499",
                     "color": "#B3DDD1"},
                    {"max": 999, "min": 500, "label": "500-999",
                     "color": "#F5B994"},
                    {"max": 9999, "min": 1000, "label": "1000-9999",
                     "color": "#EE9C6C"},
                    {"max": 10000000, "min": 9999, "label": "9999-1000000",
                     "color": "red"}]))




    tl.add(c, "{}年".format(i))
    
    
tl.render("G:/HTML图/lao_ge.html")    
#make_snapshot(snapshot, tl.render("G:/HTML图/lao_ge.html"), output_name='G:/HTML图/iii.jpg' ,pixel_ratio=3, delay=1)


Python-Pyecharts画动态图(时间+静态图)[五]_第2张图片

如有问题请联系博主!

谢谢点赞,评论!

你可能感兴趣的:(python,可视化Pyecharts,数据可视化,python)