наложение карты с другим цветом - PullRequest
0 голосов
/ 04 марта 2020

Итак, у меня есть этот геодатафрам GADM в Нидерландах, и я хочу построить наложенную карту Амстердама, Утрехта, Гааги и Роттердама разными цветами на вершине GADM Нидерландов. Но я не могу изменить цвет наложенной карты.

Это моя попытка:

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()

, и это нежелательный результат: enter image description here

Кто-нибудь может мне помочь раскрасить Амстердам, Утрехт, Гаагу и Роттердам другим цветом? спасибо

1 Ответ

0 голосов
/ 10 марта 2020

Я понял. Это так просто. Сначала извлеките нужную область каждой области GADM, которую мы хотим выделить:

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"]

Не забудьте установить ограничивающую рамку для каждой области, которую мы хотим выделить:

# 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 поверх друг друга, как это:

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')
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...