本文介绍: Python基于Pyecharts 1.X的世界地图、省、市、县(区)地图、热力图飞行航线图

首先安装对应python模块

$ pip install pyecharts 
$ pip install echartscountriespypkg
$ pip install echartschinaprovincespypkg
$ pip install echartschinacitiespypkg
$ pip install echartschinacountiespypkg

世界地图

from pyecharts import options as opts
from pyecharts.charts import Map

value = [95.1, 23.2, 43.3, 66.4, 88.5]
country = ["China", "Canada", "Brazil", "Russia", "United States"]
c = (
    Map()
        .add("世界地图", [list(z) for z in zip(country, value)], "world")
        .set_series_opts(label_opts=opts.LabelOpts(is_show=False))
        .set_global_opts(
        title_opts=opts.TitleOpts(title="Map-世界地图"),
        visualmap_opts=opts.VisualMapOpts(max_=200),
    )
        .render("map_world.html")
)

中国地图

from pyecharts import options as opts
from pyecharts.charts import Map

province_distribution = {'河南省': 45.23, '北京市': 37.56, '河北省': 21, '辽宁省': 12, '江西省': 6, '上海省': 20,
                         '安徽省': 10, '江苏省': 16, '湖南省': 9, '浙江省': 13, '海南省': 2, '广东省': 22, '湖北省': 8,
                         '黑龙江省': 11, '陕西省': 11, '四川省': 7, '内蒙古': 3, '重庆市': 3, '云南省': 6, '贵州省': 2,
                         '吉林省': 3, '山西省': 12, '山东省': 11, '福建省': 4, '青海省': 1, '天津市': 1}

provinces = list(province_distribution.keys())
values = list(province_distribution.values())
c = (
    Map()
        .add("中国地图", [list(z) for z in zip(provinces, values)], "china")
        .set_series_opts(label_opts=opts.LabelOpts(is_show=False))
        .set_global_opts(title_opts=opts.TitleOpts(title="中国地图"),
                         visualmap_opts=opts.VisualMapOpts(max_=200))
        .render("China_map.html")
)

 

省市地图

from pyecharts import options as opts
from pyecharts.charts import Map
city = ['贵阳市', '六盘水市', '遵义市', '安顺市', '毕节市', '铜仁市', '黔西南布依族苗族自治州', '黔东南苗族侗族自治州', '黔南布依族苗族自治州']
values = [1.07, 3.85, 6.38, 8.21, 2.53, 4.37, 9.38, 4.29, 6.1]
c = (
    Map()
    .add("贵州地图", [list(z) for z in zip(city, values)], "贵州")
    .set_global_opts(
        title_opts=opts.TitleOpts(title="Map-贵州地图"), visualmap_opts=opts.VisualMapOpts(max_=10)
    )
    .render("map_GuiZhou.html")
)

区县地图

import pyecharts.options as opts
from pyecharts.charts import Map
quxian = ['观山湖区', '云岩区', '南明区', '花溪区', '乌当区', '白云区', '修文县', '息烽县', '开阳县', '清镇市']
values = [3, 5, 7, 8, 2, 4, 7, 8, 2, 4]

(
    Map()
    .add(
        series_name="贵阳人口密度",
        maptype="贵阳",
        data_pair=[list(z)for z in zip(quxian,values)],
        # name_map=quxian,
        is_map_symbol_show=False,
    )
    .set_global_opts(
        title_opts=opts.TitleOpts(
            title="贵阳人口密度 (2011)",
            # subtitle="人口密度数据来自Wikipedia",
            # subtitle_link=WIKI_LINK,
        ),
        tooltip_opts=opts.TooltipOpts(
            trigger="item", formatter="{b}<br/&gt;{c} (p / km2)"
        ),
        visualmap_opts=opts.VisualMapOpts(
            min_=0,
            max_=10,
            range_text=["High", "Low"],
            is_calculable=True,
            range_color=["lightskyblue", "yellow", "orangered"],
        ),

    ).set_series_opts(label_opts=opts.LabelOpts(is_show=False))
    .render("GuiYang.html")
)


 飞行航线图

from pyecharts import options as opts
from pyecharts.charts import Geo
from pyecharts.globals import ChartType, SymbolType

c = (
    Geo(init_opts=opts.InitOpts(bg_color="#000324"))
        .add_schema(
        maptype="china",
        itemstyle_opts=opts.ItemStyleOpts(color="#323c48", border_color="#111"),
    )
        .add(
        "",
        [("广州", 55), ("兰州", 66), ("哈尔滨", 77), ("北京", 88), ("贵阳", 99), ("上海", 33), ("拉萨", 44), ("乌鲁木齐", 22)],
        type_=ChartType.EFFECT_SCATTER,
        itemstyle_opts=opts.ItemStyleOpts(),
        color="white"
    )
        .add(
        "飞行航线图",
        [("贵阳", "上海"), ("贵阳", "北京"), ("贵阳", "广州"), ("贵阳", "哈尔滨"), ("贵阳", "拉萨"), ("贵阳", "乌鲁木齐"), ("贵阳", "兰州")],
        type_=ChartType.LINES,
        effect_opts=opts.EffectOpts(
            symbol=SymbolType.ARROW, symbol_size=3, color="blue"
        ),
        linestyle_opts=opts.LineStyleOpts(curve=0.2), color="red",
    )
        .set_series_opts(label_opts=opts.LabelOpts(is_show=False))
        .set_global_opts(
        title_opts=opts.TitleOpts(title="飞行航线图", title_textstyle_opts=opts.TextStyleOpts(color="white")),  # 设置标题标题颜色
        legend_opts=opts.LegendOpts(textstyle_opts=opts.TextStyleOpts(color="white"))  # 设置图例字体颜色
    )
        .render("flay_lines.html")
)

 热力图

from pyecharts import options as opts
from pyecharts.charts import Geo
from pyecharts.faker import Faker
from pyecharts.globals import ChartType

city = ['贵阳市', '六盘水市', '遵义市', '安顺市', '毕节市', '铜仁市', '黔西南布依族苗族自治州', '黔东南苗族侗族自治州', '黔南布依族苗族自治州']
values = [1.07, 3.85, 6.38, 8.21, 2.53, 4.37, 9.38, 4.29, 6.1]
c = (
    Geo()
        .add_schema(maptype="贵州")
        .add(
        "贵州热力图",
        [list(z) for z in zip(city, values)],
        type_=ChartType.HEATMAP,
    )
        .set_series_opts(label_opts=opts.LabelOpts(is_show=False))
        .set_global_opts(
        visualmap_opts=opts.VisualMapOpts(max_=10, is_show=False), title_opts=opts.TitleOpts(title="贵州热力图")
    )
        .render("geo_GuiZhou.html")
)

原文地址:https://blog.csdn.net/zerow__/article/details/128920456

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任

如若转载,请注明出处:http://www.7code.cn/show_49663.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注