Python更新了带有国家边界的印度政治地图

问题描述 投票:0回答:1

有人能帮我绘制印度的最新政治地图,其中包括国家边界吗?底图或cartopy中的默认地图不包含有争议的区域和州边界。我现在的代码是

import cartopy as ccrs
import matplotlib.pyplot as plt
import cartopy.feature as cfeature
fig, ax = plt.subplots(subplot_kw=dict(projection=ccrs.crs.PlateCarree()))
ax.set_extent([67.0, 98.0, 5.0, 38.0])
gl = ax.gridlines(crs=ccrs.crs.PlateCarree(), draw_labels=True,
                  linewidth=1, color='gray', alpha=0.5,
                  linestyle='--')
gl.xlabels_top = False
gl.ylabels_right = False
ax.coastlines(color='black', linewidth=1, resolution='10m')
ax.add_feature(cfeature.BORDERS.with_scale('10m'),
               linestyle='-', alpha=.5)
python matplotlib geospatial matplotlib-basemap cartopy
1个回答
0
投票

您可以使用

ax.add_feature(cfeature.STATES.with_scale('10m'),
               linestyle='-', alpha=.5, color='red')

绘制州边界,但这将绘制所有国家/地区的州。

enter image description here

注:奇怪的是,当使用比例尺'50m'时,仅绘制美国,巴西和澳大利亚州。

如果需要特定国家/地区的数据,最好的方法是从GADM下载shapefile。下载并解压缩印度文件后,您可以像这样绘制:

import cartopy.crs as ccrs
import matplotlib.pyplot as plt
import cartopy.feature as cfeature
from cartopy.io.shapereader import Reader
from cartopy.feature import ShapelyFeature

fig, ax = plt.subplots(subplot_kw=dict(projection=ccrs.PlateCarree()))
ax.set_extent([67.0, 98.0, 5.0, 38.0])
gl = ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=True,
                  linewidth=1, color='gray', alpha=0.5,
                  linestyle='--')
gl.xlabels_top = False
gl.ylabels_right = False
ax.coastlines(color='black', linewidth=1, resolution='10m')
ax.add_feature(cfeature.BORDERS.with_scale('50m'),
               linestyle='-', alpha=.5)

# ax.add_feature(cfeature.STATES.with_scale('10m'),
#                linestyle='-', alpha=.5, color='red')

fname = '/tmp/india/gadm36_IND_1.shp'
shape_feature = ShapelyFeature(Reader(fname).geometries(),
                               ccrs.PlateCarree(), edgecolor='red')
ax.add_feature(shape_feature)

enter image description here

_ 0是国家级别,_1是州级别,依此类推。但我不知道如何提出有争议的地区。

© www.soinside.com 2019 - 2024. All rights reserved.