Data Visualization Second Edition - Part 03 - Chapter 10 - Geographic Features

Data Visualization Second Edition - Part 03 - Chapter 10 - Geographic Features

Summarize

This series of blogs is a teaching resource blog based on the book "Data Visualization Second Edition". This article is mainly about Chapter 10, which is related to the case of geographic feature visualization.

Visual Perspective - Geographical Features

insert image description here

insert image description here

Code

install dependencies

pip install scikit-learn -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install seaborn -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install tushare==1.2.89 -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install mplfinance==0.12.9b7 -i https://pypi.tuna.tsinghua.edu.cn/simple

Grading map

map 1

from pyecharts import options as opts
from pyecharts.charts import Map
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('density.html')
)
# 打开html
os.system("density.html")

The output is:
insert image description here

Cellular diagram

Cellular Diagram 1-

import matplotlib.pyplot as plt
import numpy as np

# create data
x = np.random.normal(size=50000)
y = (x * 3 + np.random.normal(size=50000)) * 5

fig,axes  = plt.subplots(1,2)


# Control the color
axes[0].hexbin(x, y, gridsize=(25, 25), cmap=plt.cm.Greens)
# plt.show()
# Other color
axes[1].hexbin(x, y, gridsize=(25, 25), cmap=plt.cm.BuGn_r)
plt.show()

insert image description here

Deformation map

Reference:
How to elegantly choose a map deformation method

1 Introduction to Cartogram
2 ArcGIS Cartogram Toolbox
3 QGIS Cartogram Plugin
4 Cartogram in R
5 GeoDa and geofacet

Associated map

Associated map 1

from pyecharts import options as opts
from pyecharts.charts import Geo  # 地理坐标系绘制方法
from pyecharts.globals import GeoType, ThemeType, SymbolType  # Geo图的类型 主题 图形符号
import os

data = [("广州", "8302"), ("河源", "10006"), ("东莞", "9559"), ("汕头", "6860"), ("珠海", "11169")]
geo = (
    Geo(init_opts=opts.InitOpts(width="600px", height="500px", theme=ThemeType.WHITE))  # 设置画板
        .add_schema(maptype="广东",  # 生成广东省的地图
                    emphasis_itemstyle_opts=opts.ItemStyleOpts(color="#31708f"),  # 高亮颜色
                    )

        .add("",  # 读入数据,生成几个城市的点
             data,
             type_=GeoType.EFFECT_SCATTER,
             symbol_size=6
             )
        .add("",  # 建立联系
             [("广州", "河源"), ("广州", "东莞"), ("广州", "汕头"), ("广东", "珠海")],
             type_=GeoType.LINES,
             effect_opts=opts.EffectOpts(symbol=SymbolType.ARROW, symbol_size=6, color='#5f99bb'),
             linestyle_opts=opts.LineStyleOpts(curve=0.2, color="#B0E2FF"))
        .set_series_opts(label_opts=opts.LabelOpts(is_show=False))
        .set_global_opts(
        title_opts=opts.TitleOpts(title="广州出发的航班", pos_right="center", pos_top="5%"))
        .render('linked.html'))
os.system('linked.html')

insert image description here

bubble map

Bubble Map 1-

import os
from pyecharts import options as opts
from pyecharts.charts import Geo


# 2018末人口数
data = [("广州", 14.9), ("深圳", 13.03), ("东莞", 8.39), ("汕头", 5.64), ("珠海", 1.89)]
rate = [("广州", 33.98), ("深圳", 29.71), ("东莞", 19.13), ("汕头", 12.86), ("珠海", 4.31)]
c = Geo()
c.add_schema(maptype='广东')  # 生成广东省地图
c.add('', rate)  # 导入数据:rate
c.set_global_opts(visualmap_opts=opts.VisualMapOpts(type_='size'),  # 可视化
                  title_opts=opts.TitleOpts(title="2018年广东省五市人口数比例", pos_right="center",
                                            pos_top="5%"))  # 使size由气泡大小呈现出来
c.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
c.render('bubble.html')
os.system('bubble.html')

insert image description here

Textbook screenshot

insert image description here

Guess you like

Origin blog.csdn.net/m0_38139250/article/details/129988853