Pyecharts绘制地图(世界地图,城市地图,热力图)

一. pyechart绘制世界地图(城市地图,热力图)

1.1 pyechart绘制世界地图
from pyecharts import options as opts
from pyecharts.charts import Map
from pyecharts.faker import Faker
import os

# 基础数据
value = [95.1, 23.2, 43.3, 66.4, 88.5]
attr = ["China", "Canada", "Brazil", "Russia", "United States"]

data = []
for index in range(len(attr)):
    city_ionfo=[attr[index],value[index]]
    data.append(city_ionfo)

c = (
    Map()
    .add("世界地图",data, "world")
    .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()
)

# 打开html
os.system("render.html")
1.2 pyechart绘制城市地图
# _*_ coding: utf-8 _*_
# !/usr/bin/python
"""
Author:mym
Create Date: -11:28
User: EDZ
description:
"""


from pyecharts import options as opts
from pyecharts.charts import Map
from pyecharts.faker import Faker
import os


class CityLocate:

    def __init__(self):
        self.province_distribution = \
            {
     '河南': 45.23, '北京': 37.56, '河北': 21, '辽宁': 12, '江西': 6, '上海': 20, '安徽': 10, '江苏': 16, '湖南': 9,
             '浙江': 13, '海南': 2, '广东': 22, '湖北': 8, '黑龙江': 11, '澳门': 1, '陕西': 11, '四川': 7, '内蒙古': 3,
             '重庆': 3, '云南': 6, '贵州': 2, '吉林': 3, '山西': 12, '山东': 11, '福建': 4, '青海': 1, '舵主科技,质量保证': 1,
             '天津': 1, '其他': 1
             }

        self.provinces = list(self.province_distribution.keys())
        self.city_numbers = list(self.province_distribution.values())

    def render_data(self):
        c = (
            Map().add("", [list(z) for z in zip(self.provinces, self.city_numbers)], "china")
                .set_global_opts(title_opts=opts.TitleOpts(title="中国地图")).render()
        )
        os.system('render.html')


if __name__ == '__main__':
    # CityLocate().render_data()
1.3 pyecharts绘制热力图
from pyecharts import options as opts
from pyecharts.charts import Geo
from pyecharts.faker import Faker
from pyecharts.globals import ChartType
import os

# 基础数据
keys = ['上海', '北京', '合肥', '哈尔滨', '广州', '成都', '无锡', '杭州', '武汉', '深圳', '西安', '郑州', '重庆', '长沙', '贵阳', '乌鲁木齐']

values = [4.07, 1.85, 4.38, 2.21, 3.53, 4.37, 1.38, 4.29, 4.1, 1.31, 3.92, 4.47, 2.40, 3.60, 1.2, 3.7]

c = (
    Geo()
    .add_schema(maptype="china")
    .add(
        "空气质量热力图",
        [list(z) for z in zip(keys, values)],
        type_=ChartType.EFFECT_SCATTER,
    )
    .set_series_opts(label_opts=opts.LabelOpts(is_show=False))
    .set_global_opts(title_opts=opts.TitleOpts(title="全国主要城市空气质量热力图"))
    .render()
)

# 打开html
os.system("render.html")

你可能感兴趣的:(python)