silent_hunter
silent_hunter

Reputation: 2508

Map with sub regions in Python (Choropleth)

I am trying to plot a Choropleth map with subregions in Python for Armenia. Below you can see my data.

import numpy as np
import pandas as pd
import geopandas as gpd
import matplotlib.pyplot as plt

data_arm = {
         'subregion': ['Aragatsotn','Ararat','Armavir','Gegharkunik','Kotayk','Lori','Shirak','Syunik','Tavush','Vayots Dzor','Yerevan'],
         'Value':[0.2560,0.083,0.0120,0.9560,0.423,0.420,0.2560,0.043,0.0820,0.4560,0.019]
        }

df = pd.DataFrame(data_arm, columns = ['subregion',
                                   'Value'                                   
                                   ])
df

Namely, I want to plot a map for Armenia with all subregions. Unfortunately, I don't know how to implement it in this environment. Below you will see the code where I tried to do something

world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))

asia = world.query('continent == "Asia"')

EAC = ["ARM"]

asia["EAC"] = np.where(np.isin(asia["iso_a3"], EAC), 1, 0)

asia.plot(column="iso_a3")
plt.show()

So can anybody help me how to solve this problem and make Choropleth map similar as Choropleth map shown below: enter image description here

Upvotes: 0

Views: 548

Answers (1)

Rob Raymond
Rob Raymond

Reputation: 31226

You need to get geometry of sub-regions. I used https://data.humdata.org/dataset/geoboundaries-admin-boundaries-for-armenia?

Then just need to join / merge to your data frame.

import pandas as pd

import geopandas as gpd

data_arm = {
    "subregion": [
        "Aragatsotn",
        "Ararat",
        "Armavir",
        "Gegharkunik",
        "Kotayk",
        "Lori",
        "Shirak",
        "Syunik",
        "Tavush",
        "Vayots Dzor",
        "Yerevan",
    ],
    "Value": [
        0.2560,
        0.083,
        0.0120,
        0.9560,
        0.423,
        0.420,
        0.2560,
        0.043,
        0.0820,
        0.4560,
        0.019,
    ],
}

df = pd.DataFrame(data_arm, columns=["subregion", "Value"])

gdf = gpd.read_file(
    "https://github.com/wmgeolab/geoBoundaries/raw/3c96fa7257a71fbc6cb85284d36d2894e1882ff6/releaseData/gbOpen/ARM/ADM1/geoBoundaries-ARM-ADM1_simplified.geojson"
)

gdf.merge(df, left_on="shapeName", right_on="subregion").explore("Value")

enter image description here

Upvotes: 1

Related Questions