相关文章推荐
纯真的冲锋衣  ·  数据争用(data race) ...·  3 月前    · 
温暖的弓箭  ·  11_vue计算属性computed_vue ...·  2 月前    · 
彷徨的充电器  ·  computed, watch, ...·  2 月前    · 
年轻有为的楼房  ·  为select标签绑定onchange事件_ ...·  2 月前    · 
粗眉毛的熊猫  ·  jquery ajax向spring ...·  2 月前    · 
打酱油的排球  ·  WORD必学技巧:使用项目编号-阿里云开发者社区·  8 月前    · 
烦恼的野马  ·  fatal error: ...·  1 年前    · 
私奔的柳树  ·  深度网络中的Tricks - 冬色 - 博客园·  1 年前    · 
活泼的弓箭  ·  SSE (EventSource) · ...·  1 年前    · 
失眠的匕首  ·  Arduino编程工具上传失败怎么办-百度经验·  1 年前    · 
Code  ›  Python 如何画出漂亮的地图? - 易执 的回答 -
python data
https://www.zhihu.com/question/33783546/answer/969110549
爱看书的签字笔
1 年前
Python 如何画出漂亮的地图?
易执
易执

作为一个颜控,看到这个问题可谓是非常感兴趣了,在这里推荐两个 比较冷门但绘图效果很棒 的库: Altair 和 GeoViews 。

  • Altair

Altair 类似于Seaborn,主要用于 统计可视化, 是一种声明性统计可视化库,是JavaScript的高级可视化库Vega-Lite的包装器。Altair可以画很多种图形,这里主要介绍一下Altair的地图绘制部分。

Altair中用简单的代码就可以绘制超级好看的 Choropleth Map(地区分级统计图)

import altair as alt
from vega_datasets import data
counties = alt.topo_feature(data.us_10m.url, 'counties')
source = data.unemployment.url
alt.Chart(counties).mark_geoshape().encode(
    color='rate:Q'
).transform_lookup(
    lookup='id',
    from_=alt.LookupData(source, 'id', ['rate'])
).project(
    type='albersUsa'
).properties(
    width=500,
    height=300
)

Altair中生成带经纬度的世界地图

# Data generators for the background
sphere = alt.sphere()
graticule = alt.graticule()
# Source of land data
source = alt.topo_feature(data.world_110m.url, 'countries')
# Layering and configuring the components
alt.layer(
    alt.Chart(sphere).mark_geoshape(fill='lightblue'),
    alt.Chart(graticule).mark_geoshape(stroke='white', strokeWidth=0.5),
    alt.Chart(source).mark_geoshape(fill='ForestGreen', stroke='ForestGreen')
).project(
    'naturalEarth1'
).properties(width=600, height=400).configure_view(stroke=None)

从不同的视角展现世界地图

美国的邮编分布图

还能绘制 伦敦地铁线路图

想深入学习的同学可以参见官方文档


  • GeoViews

相比Altair而言, GeoViews 更专注于地理数据的可视化。运用GeoViews,可以很容易地对 地理 、 气象 和 海洋 数据集进行探索和可视化,其也常被应用于 天气、气候和遥感 的研究。

GeoView既可以结合bokeh生成动态的地理图,也可以结合matplotlib绘制静态图。

1、绘图呈现 地表温度变化

import geoviews as gv
import geoviews.feature as gf
import xarray as xr
from cartopy import crs
gv.extension('matplotlib')
# Define data
ensemble = xr.open_dataset('../../data/ensemble.nc')
dataset = gv.Dataset(ensemble, ['longitude', 'latitude', 'time'], 'surface_temperature', crs=crs.PlateCarree())
images = dataset.to(gv.Image)
# plot
images.opts(cmap='viridis', colorbar=True, fig_size=250) * gf.coastline

2、英国脱欧公投票数地区分布

geometries = gpd.read_file('../../assets/boundaries/boundaries.shp')
 
推荐文章
纯真的冲锋衣  ·  数据争用(data race) 和竞态条件(race condition)
3 月前
温暖的弓箭  ·  11_vue计算属性computed_vue2 computed加载时执行两次
2 月前
彷徨的充电器  ·  computed, watch, update 的使用和区别 - sunshine233
2 月前
年轻有为的楼房  ·  为select标签绑定onchange事件_1、给 id为“qval”的 select 标签添加值改变事件。 (1)绑定 onchange 事件
2 月前
粗眉毛的熊猫  ·  jquery ajax向spring mvc controller中传值并接受及解析返回值_fineu jquery前台调用control 并返回值
2 月前
打酱油的排球  ·  WORD必学技巧:使用项目编号-阿里云开发者社区
8 月前
烦恼的野马  ·  fatal error: sys/sysctl.h: 没有那个文件或目录 #include <sys/sysctl.h> (JVM)Linux下编译openjdk-8报错_fatal error: s
1 年前
私奔的柳树  ·  深度网络中的Tricks - 冬色 - 博客园
1 年前
活泼的弓箭  ·  SSE (EventSource) · PHP/Python/前端/Linux 等等 学习笔记 · 看云
1 年前
失眠的匕首  ·  Arduino编程工具上传失败怎么办-百度经验
1 年前
今天看啥   ·   Py中国   ·   codingpro   ·   小百科   ·   link之家   ·   卧龙AI搜索
删除内容请联系邮箱 2879853325@qq.com
Code - 代码工具平台
© 2024 ~ 沪ICP备11025650号