Reputation: 73
I have data which looks like:
OBJECTID,"ID_0","ISO","NAME_0","ID_1","NAME_1","ID_2","NAME_2","TYPE_2","ENGTYPE_2","NL_NAME_2","VARNAME_2"
1,158,"NLD","Netherlands",1,"Drenthe",1,"Aa en Hunze","Gemeente","Municipality",NA,NA
2,158,"NLD","Netherlands",1,"Drenthe",2,"Assen","Gemeente","Municipality",NA,NA
etc.
This gives a plot of the Netherlands with the different 'gemeentes'.
Now I have data per gemeente in numbers. So in example:
Aa en Hunze: 150
Assen: 125
etc.
Can I combine this data with my plot? So for example, the higher te number, the more red the gemeente will be in the plot? Or something equal?
Upvotes: 2
Views: 225
Reputation: 1949
import geopandas as gpd
import numpy as np
df = gpd.read_file(r"C:/Users/bera/Desktop/gistest/Africa.geojson")
#Addition data stored in a dict
data = {'Togo': 7, 'Benin': 2, 'Malawi': 3, 'Tunisia': 7, 'Gambia': 2, 'Dem. Rep. Congo': 4, 'S. Sudan': 1, 'eSwatini': 9, 'Liberia': 8,
'Morocco': 5, 'South Africa': 9, 'Zambia': 4, 'Chad': 5, 'Niger': 8, 'Angola': 8, 'Lesotho': 6, 'Cameroon': 4, "Côte d'Ivoire": 8,
'Mauritania': 9, 'Senegal': 9, 'Sierra Leone': 7, 'Kenya': 7, 'Rwanda': 4, 'Nigeria': 3, 'Eq. Guinea': 8, 'Central African Rep.': 5,
'Djibouti': 4, 'Egypt': 4, 'Sudan': 6, 'Guinea': 7, 'Congo': 6, 'Ethiopia': 1, 'Tanzania': 2, 'Burundi': 8, 'Algeria': 7,
'Somalia': 3, 'Mali': 1, 'Ghana': 1, 'Namibia': 4, 'Eritrea': 1, 'Libya': 8, 'Botswana': 3, 'Mozambique': 4, 'Guinea-Bissau': 4,
'Gabon': 9, 'Burkina Faso': 1, 'Uganda': 5, 'Zimbabwe': 1, 'W. Sahara': 5}
#Create a new column using the dict
df["data"] = df.NAME.map(data)
#Plot
ax = df.plot(column="data", cmap="Reds", figsize=(10,10), edgecolor="black", legend=True)
Upvotes: 0