地理空间数据可视化

地理空间数据可视化

地理可视化,是指一组的工具和技术支持的分析地理空间数据通过使用交互式可视化。像科学可视化和信息可视化的相关领域一样, 地理可视化强调知识在知识存储或信息传递上的构建。为此,地理可视化以与人类理解相结合的方式传达地理空间信息,从而允许进行数据探索和决策过程。

环境准备

本文所做的数据的数据可视化实现基于python 3.9.4,需安装matplotlib、numpy、pyecharts、pandas等依赖库,可通过下述命令完成。

pip install matplotlib
pip install numpy
pip install -v pyecharts==1.1.0
pip install pandas

地图

使用地图作为背景,通过图形位置来表现数据的地理位置,将数据在不同地理位置上的分布通过颜色或者气泡映射在地图上。

场景:适合带有地理位置信息的数据集展现,展现的通常是以某个地区为单位的汇总连续值信息

优点

  • 和地图相结合,对数据的地理分布显示直观

  • 通过颜色的深浅、气泡的大小等容易判断度量的大小

缺点

  • 必须有地理信息,且数据为汇总数据,气泡容易叠加

  • 显示的都是非精确值,气泡大小和颜色深浅相近时不易分辨

  • 地理面积大小和度量值无关,容易误读

类似图表:气泡地图、颜色地图(分级统计地图)、描点地图

示例

import requests
import json
from pyecharts.charts import Map, Geo
from pyecharts import options as opts
from pyecharts.globals import GeoType

# To obtain COVID-19 data, the data source is obtained from Tencent News 
# through crawlers, you can be modify the source as needed and process
# data according to the format of the source 
url = 'https://view.inews.qq.com/g2/getOnsInfo?name=disease_h5'
report = json.loads(requests.get(url).json()['data'])
last_update_time = report['lastUpdateTime']
# China's overall COVID-19 data
china_total = report['chinaTotal']
# COVID-19 data of China provinces
China = report['areaTree'][0]['children']
# map title
map_title = '确诊:{} 疑似:{} 死亡:{} 治愈:{} \n更新日期:{}'.format(
    china_total['confirm'],
    china_total['suspect'],
    china_total['dead'],
    china_total['heal'],
    last_update_time
)
# confirm number of China provinces
virus_list = [list([China[i]['name'], China[i]['total']['confirm']]) for i in range(len(China))]

c = (
    Geo()
    .add_schema(
        maptype='china',
        # Set the map area color
        itemstyle_opts=opts.ItemStyleOpts(
            color="#323c48", border_color="#111"),
    )
    .add(
        'geo',
        virus_list,
        # Set the ripple effect
        type_=GeoType.EFFECT_SCATTER,
    )
    .set_series_opts(
        label_opts=opts.LabelOpts(is_show=False),
    )
    .set_global_opts(
        # Set the title, subtitle, and center
        title_opts=opts.TitleOpts(
            title="全国疫情地图", subtitle=map_title, pos_left='center'),
        # Set the gradient and set the maximum value to the average
        visualmap_opts=opts.VisualMapOpts(
            min_=0, max_=china_total['confirm']/len(report)),
        # Do not display legends
        legend_opts=opts.LegendOpts(is_show=False)
    )
)

c.render(path="china_virus_map1.html")

# Map of daily confirmed cases in China
virus_map = Map()
virus_map.add(map_title, virus_list)
virus_map.set_global_opts(visualmap_opts=opts.VisualMapOpts(split_number=6, is_piecewise=True,
                                                            pieces=[{
    
    "min": 1, "max": 9, "label": "1-9人", "color": "#ffefd7"},
                                                                    {
    
    "min": 10, "max": 99, "label": "10-99人", "color": "#ffd2a0"},
                                                                    {
    
    "min": 100, "max": 499, "label": "100-499人", "color": "#fe8664"},
                                                                    {
    
    "min": 500, "max": 999, "label": "500-999人", "color": "#e64b47"},
                                                                    {
    
    "min": 1000, "max": 9999, "label": "1000-9999人", "color": "#c91014"},
                                                                    {
    
    "min": 10000, "label": "10000人以上", "color": "#9c0a0d"}]),
                          title_opts=opts.TitleOpts(title="中国每日确认病例地图"))
virus_map.render(path="china_virus_map2.html")

在这里插入图片描述
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/yefufeng/article/details/123972565
今日推荐