在python底图中填充国家/地区 [英] Fill countries in python basemap

查看:35
本文介绍了在python底图中填充国家/地区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 python 底图绘制地图,其中一些国家填充了某种颜色.

Hi I am trying to plot a map using pythons basemap with some countries filled in a certain colour.

是否有快速简便的解决方案?

Is there a quick and easy solution out there??

推荐答案

正如@unutbu 所说,Thomas 的帖子 这里正是您所追求的.

As has already been said by @unutbu, Thomas' post here is exactly what you are after.

如果你想用 Cartopy 做到这一点,相应的代码(在 v0.7 中)可以改编自 http://scitools.org.uk/cartopy/docs/latest/tutorials/using_the_shapereader.html 稍微:

Should you want to do this with Cartopy, the corresponding code (in v0.7) can be adapted from http://scitools.org.uk/cartopy/docs/latest/tutorials/using_the_shapereader.html slightly:

import cartopy.crs as ccrs
import matplotlib.pyplot as plt
import cartopy.io.shapereader as shpreader
import itertools
import numpy as np

shapename = 'admin_0_countries'
countries_shp = shpreader.natural_earth(resolution='110m',
                                        category='cultural', name=shapename)

# some nice "earthy" colors
earth_colors = np.array([(199, 233, 192),
                                (161, 217, 155),
                                (116, 196, 118),
                                (65, 171, 93),
                                (35, 139, 69),
                                ]) / 255.
earth_colors = itertools.cycle(earth_colors)



ax = plt.axes(projection=ccrs.PlateCarree())
for country in shpreader.Reader(countries_shp).records():
    print country.attributes['name_long'], earth_colors.next()
    ax.add_geometries(country.geometry, ccrs.PlateCarree(),
                      facecolor=earth_colors.next(),
                      label=country.attributes['name_long'])

plt.show()

这篇关于在python底图中填充国家/地区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆