首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >具有不同颜色的叠加地图

具有不同颜色的叠加地图
EN

Stack Overflow用户
提问于 2020-03-04 21:46:53
回答 1查看 75关注 0票数 0

我有一个荷兰的GADM地理数据框架,我想在荷兰的GADM上绘制阿姆斯特丹,乌得勒支,海牙和鹿特丹的不同颜色的叠加图。但是,我不能更改叠加贴图的颜色。

这是我的尝试:

代码语言:javascript
复制
NL_boundaries = gpd.read_file("C:/Users/zaa_k/Documents/0.Thesis/Datasets/GADM/gadm36_NLD_2.shp")

NL_boundaries_Ams = NL_boundaries[NL_boundaries['NAME_2']=='Amsterdam']
NL_boundaries_Ams = NL_boundaries[NL_boundaries['NAME_2']=='Rotterdam']
NL_boundaries_Ut = NL_boundaries[NL_boundaries['NAME_2']=='Utrecht']
NL_boundaries_Hag = NL_boundaries[NL_boundaries['NAME_2']=="'s-Gravenhage"]

f, ax = plt.subplots(1, figsize=(12, 12))
ax = NL_boundaries.plot(axes=ax)
lims = plt.axis('equal')
for poly in NL_boundaries['geometry']:
    gpd.plotting.plot_multipolygon(ax, poly, facecolor='red', linewidth=0.025)
for poly in NL_boundaries_Ams['geometry']:
    gpd.plotting.plot_multipolygon(ax, poly, alpha=1, facecolor='red', linewidth=0)
for poly in NL_boundaries_Ut['geometry']:
    gpd.plotting.plot_multipolygon(ax, poly, alpha=1, facecolor='red', linewidth=0)
for poly in NL_boundaries_Rot['geometry']:
    gpd.plotting.plot_multipolygon(ax, poly, alpha=1, facecolor='red', linewidth=0)
for poly in NL_boundaries_Hag['geometry']:
    gpd.plotting.plot_multipolygon(ax, poly, alpha=1, facecolor='red', linewidth=0)
ax.set_axis_off()
f.suptitle('Areas with smallest population')
plt.axis('equal')
plt.show()

这就是不希望看到的结果:

谁能帮我把阿姆斯特丹、乌得勒支、海牙和鹿特丹涂成其他颜色?谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-03-10 14:34:50

我有个主意。就是这么简单。首先,提取我们想要突出显示的每个GADM区域的所需区域:

代码语言:javascript
复制
NL_boundaries = gpd.read_file("C:/Users/zaa_k/Documents/0.Thesis/Datasets/GADM/gadm36_NLD_2.shp")
NL_boundaries_Ams = NL_boundaries[NL_boundaries['NAME_2']=='Amsterdam']
NL_boundaries_Rot = NL_boundaries[NL_boundaries['NAME_2']=='Rotterdam']
NL_boundaries_Ut = NL_boundaries[NL_boundaries['NAME_2']=='Utrecht']
NL_boundaries_Hag = NL_boundaries[NL_boundaries['NAME_2']=="'s-Gravenhage"]

不要忘记设置我们想要突出显示的每个区域的边界框:

代码语言:javascript
复制
# Bounding Box four cities
NL_boundaries_Ams.total_bounds
NL_boundaries_Rot.total_bounds
NL_boundaries_Ut.total_bounds
NL_boundaries_Hag.total_bounds
xlim = ([NL_boundaries_Rot.total_bounds[0],  NL_boundaries_Ut.total_bounds[2]])
ylim = ([NL_boundaries_Rot.total_bounds[1],  NL_boundaries_Ams.total_bounds[3]])

然后像这样将GADM区域的每一层逐个绘制出来:

代码语言:javascript
复制
f, ax = plt.subplots(1, figsize=(25, 25))
ax.set_xlim(xlim)
ax.set_ylim(ylim)
ax = NL_boundaries.plot(axes=ax, alpha=0.1, edgecolor= 'k')
ax = NL_boundaries_Ams.plot(axes=ax, alpha=1)
ax = NL_boundaries_Rot.plot(axes=ax, alpha=1)
ax = NL_boundaries_Ut.plot(axes=ax, alpha=1)
ax = NL_boundaries_Hag.plot(axes=ax, alpha=1)
ax = dataPoints0.plot(axes=ax, color='red')
ax = dataPoints1.plot(axes=ax, color='cyan')
ax = dataPoints2.plot(axes=ax, color='magenta')
ax = dataPoints3.plot(axes=ax, color='orange')
ax = dataPoints4.plot(axes=ax, color='black')
ax = dataPoints5.plot(axes=ax, color='lime')
ax = dataPoints6.plot(axes=ax, color='blueviolet')
ax = dataPoints7.plot(axes=ax, color='turquoise')

plt.title('K-cluster = 8')
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60527554

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档