ベースの地図が出来た所で、他のデータを被せてみます。
国土地理院の 500mメッシュ別将来推計人口データ を使用します。
同じく神奈川県のデータ 500m_mesh_suikei_2018_shape_14.zip をダウンロードします。
ベースの地図データと同じ場所に展開します。
そして同じようにread_fileで読み込みます。
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
import geopandas as gpd
import matplotlib.pyplot as plt
import japanize_matplotlib
fn = "../data/N03-20240101_14.shp"
gdf = gpd.read_file(fn)
fn2 = "../data/500m_mesh_2018_14.shp"
pdf = gpd.read_file(fn2)
print(gdf.head(10))
print("")
print(gdf.shape)
print("")
print(pdf.head())
print("")
print(pdf.shape)
(6193, 235)と巨大なデータフレームなので、必要なデータ以外は取り除いてもいいでしょう。
# 必要な列だけ取り出し軽量化します。
pdf2 = pdf[['SHICODE', 'PTN_2020', 'geometry']]
# ベースとなる地図
bg = gdf.boundary.plot(linewidth=0.5, edgecolor="gray", figsize=(14, 8))
# 人口データのプロット
pdf2.plot(ax=bg, column="PTN_2020", cmap="jet", legend=True)
# 地域名を表示
for name, row in citys:
if row['N03_001'].count() > 1:
x = row["geometry"].centroid.bounds.minx.mean()
y = row["geometry"].centroid.bounds.miny.mean()
bg.annotate(name, xy=(x, y), color="red")
else:
x = row["geometry"].centroid.bounds.minx
y = row["geometry"].centroid.bounds.miny
bg.annotate(name, xy=(x, y), color="red")
plt.title("神奈川県人口マップ")
plt.show()
地図データに人口データを重ね合わせることが出来ました。

