一、导读
Python地图可视化库有大家熟知的pyecharts、plotly、folium,其他还有稍低调的bokeh、basemap、geopandas,也是地图可视化的利器。
二、pyecharts
1、中国地图
链式调用
# -*- coding: utf-8 -*-
from pyecharts.charts import Map,Geo
from pyecharts import options as opts
data=[("广东",10430.03),("山东",9579.31),("河南",9402.36),("四川",8041.82),("江苏",7865.99),("河北",7185.42),("湖南",6568.37),("安徽",5950.1),("浙江",5442),("湖北",5723.77),("广西",4602.66),("云南",4596.6),("江西",4456.74),("辽宁",4374.63),("黑龙江",3831.22),("陕西",3732.74),("山西",3571.21),("福建",3552),("重庆",2884),("贵州",3476.65),("吉林",2746.22),("甘肃",2557.53),("内蒙古",2470.63),("上海",2301.391),("台湾",2316.2),("新疆",2181.33),("北京",1961.2),("天津",1293.82),("海南",867.15),("香港",709.76),("青海",562.67),("宁夏",630.14),("西藏",300.21),("澳门",55.23)]
map=(
Map()
.add("",data,"china")
.set_global_opts(
title_opts=opts.TitleOpts(title="各省市人口数",subtitle="数据来源:中国统计年鉴(万人)",pos_right="center",pos_top="5%"),
visualmap_opts=opts.VisualMapOpts(max_=12000),
)
)
map.render('map_qg.html')
#单独调用
# from pyecharts.charts import Map,Geo
# from pyecharts import options as opts
# data=[("广东",10430.03),("山东",9579.31),("河南",9402.36),("四川",8041.82),("江苏",7865.99),("河北",7185.42),("湖南",6568.37),("安徽",5950.1),("浙江",5442),("湖北",5723.77),("广西",4602.66),("云南",4596.6),("江西",4456.74),("辽宁",4374.63),("黑龙江",3831.22),("陕西",3732.74),("山西",3571.21),("福建",3552),("重庆",2884),("贵州",3476.65),("吉林",2746.22),("甘肃",2557.53),("内蒙古",2470.63),("上海",2301.391),("台湾",2316.2),("新疆",2181.33),("北京",1961.2),("天津",1293.82),("海南",867.15),("香港",709.76),("青海",562.67),("宁夏",630.14),("西藏",300.21),("澳门",55.23)]
# map=Map()
# map.add("",data,"china")
# map.set_global_opts(
# title_opts=opts.TitleOpts(title="各省市人口数",subtitle="数据来源:中国统计年鉴(万人)",pos_right="center",pos_top="5%"),
# visualmap_opts=opts.VisualMapOpts(max_=12000),
# )
# map.render('map_qg.html')
图:
2、省市地图
from pyecharts.charts import Map
from pyecharts im