Créez une carte choroplèthe¶

Carte de population de Bouira¶

Une carte choroplèthe (du grec χῶρος : « zone/région » et πλῆθος : « grand nombre, multitude ») est une carte thématique où les régions sont colorées ou remplies d'un motif qui montre une mesure statistique, tels la densité de population ou le revenu par habitant. Ce type de carte facilite la comparaison d'une mesure statistique d'une région à l'autre ou montre la variabilité de celle-ci pour une région donnée.wikipedia

Préparation de données¶

Nous allos créer une carte choplèthe pour visualiser géographiquement la population de Bouira, et pour cela il faut avoir la frontière Administrative de Bouira et aussi télécharger le fichier CSV de la Populations de Bouira

Source du fichier popultion: ONS

In [1]:
import geopandas as gpd
import pandas as pd
In [2]:
path_to_data ="./data/wbouira.shp"
gdf = gpd.read_file(path_to_data)

gdf
Out[2]:
ID_0 ISO NAME_0 ID_1 NAME_1 ID_2 NAME_2 TYPE_2 ENGTYPE_2 X Y Population superficie geometry
0 5 DZA Algeria 12 Bouira 353 AGHBALOU Commune Commune None None None None POLYGON ((478679.140 4354598.121, 478546.437 4...
1 5 DZA Algeria 12 Bouira 354 AHL-EL-KSAR Commune Commune None None None None POLYGON ((458096.559 4339404.491, 458085.518 4...
2 5 DZA Algeria 12 Bouira 355 AHNIF Commune Commune None None None None POLYGON ((473835.421 4332764.866, 473715.086 4...
3 5 DZA Algeria 12 Bouira 356 AIN-BESSEM Commune Commune None None None None POLYGON ((410218.793 4335155.776, 410175.479 4...
4 5 DZA Algeria 12 Bouira 357 AIN-EL-HADJAR Commune Commune None None None None POLYGON ((426730.571 4349243.480, 426751.618 4...
5 5 DZA Algeria 12 Bouira 358 AIN-LALOUI Commune Commune None None None None POLYGON ((414504.920 4348625.545, 414544.439 4...
6 5 DZA Algeria 12 Bouira 359 AIN-TURK Commune Commune None None None None POLYGON ((428803.448 4359789.178, 428789.328 4...
7 5 DZA Algeria 12 Bouira 360 AIT-LAAZIZ Commune Commune None None None None POLYGON ((438557.715 4363083.038, 438550.470 4...
8 5 DZA Algeria 12 Bouira 361 AOMAR Commune Commune None None None None POLYGON ((427249.759 4363316.919, 427215.814 4...
9 5 DZA Algeria 12 Bouira 362 ATH-MANSOUR Commune Commune None None None None POLYGON ((476926.874 4347296.472, 476937.331 4...
10 5 DZA Algeria 12 Bouira 363 BECHLOUL Commune Commune None None None None POLYGON ((448654.516 4340431.766, 448587.580 4...
11 5 DZA Algeria 12 Bouira 364 BIR-GHBALOU Commune Commune None None None None POLYGON ((405529.010 4338312.000, 405500.293 4...
12 5 DZA Algeria 12 Bouira 365 BORDJ-OKHRISS Commune Commune None None None None POLYGON ((426167.406 4307012.819, 426155.834 4...
13 5 DZA Algeria 12 Bouira 366 BOUDERBALA Commune Commune None None None None POLYGON ((392844.922 4384172.391, 393300.784 4...
14 5 DZA Algeria 12 Bouira 367 BOUIRA Chef-Lieu-Wilaya Chef-Lieu-Wilaya None None None None POLYGON ((426730.571 4349243.480, 426779.672 4...
15 5 DZA Algeria 12 Bouira 368 BOUKRAM Commune Commune None None None None POLYGON ((367367.903 4376059.806, 367446.384 4...
16 5 DZA Algeria 12 Bouira 369 CHORFA Commune Commune None None None None POLYGON ((482711.458 4348736.265, 482508.635 4...
17 5 DZA Algeria 12 Bouira 370 DECHMIA Commune Commune None None None None POLYGON ((408931.705 4328727.688, 408930.484 4...
18 5 DZA Algeria 12 Bouira 371 DIRRAH Commune Commune None None None None POLYGON ((425063.899 4306334.275, 424907.601 4...
19 5 DZA Algeria 12 Bouira 372 DJEBAHIA Commune Commune None None None None POLYGON ((420478.102 4359749.067, 420458.276 4...
20 5 DZA Algeria 12 Bouira 373 EL-ADJIBA Commune Commune None None None None POLYGON ((460499.867 4340479.707, 460328.679 4...
21 5 DZA Algeria 12 Bouira 374 EL-ASNAM Commune Commune None None None None POLYGON ((448654.516 4340431.766, 448578.928 4...
22 5 DZA Algeria 12 Bouira 375 EL-HACHIMIA Commune Commune None None None None POLYGON ((422183.497 4320581.606, 422180.949 4...
23 5 DZA Algeria 12 Bouira 376 EL-HAKIMIA Commune Commune None None None None POLYGON ((426167.406 4307012.819, 426180.092 4...
24 5 DZA Algeria 12 Bouira 377 EL-KHABOUZIA Commune Commune None None None None POLYGON ((406837.782 4338739.186, 406761.875 4...
25 5 DZA Algeria 12 Bouira 378 EL-MOKRANI Commune Commune None None None None POLYGON ((396860.440 4360082.101, 396878.913 4...
26 5 DZA Algeria 12 Bouira 379 GUERROUMA Commune Commune None None None None POLYGON ((389988.008 4371789.183, 389836.169 4...
27 5 DZA Algeria 12 Bouira 380 HADJERA-ZERGA Commune Commune None None None None POLYGON ((426299.313 4306507.583, 426368.239 4...
28 5 DZA Algeria 12 Bouira 381 HAIZER Commune Commune None None None None POLYGON ((438349.557 4351516.227, 438372.700 4...
29 5 DZA Algeria 12 Bouira 382 KADIRIA Commune Commune None None None None POLYGON ((405093.292 4365529.805, 405058.232 4...
30 5 DZA Algeria 12 Bouira 383 LAKHDARIA Commune Commune None None None None POLYGON ((400237.763 4373757.549, 400226.191 4...
31 5 DZA Algeria 12 Bouira 384 M'CHEDALLAH Commune Commune None None None None POLYGON ((464933.002 4354447.250, 465100.739 4...
32 5 DZA Algeria 12 Bouira 385 MAALA Commune Commune None None None None POLYGON ((397325.432 4361620.207, 397313.277 4...
33 5 DZA Algeria 12 Bouira 386 MAAMOURA Commune Commune None None None None POLYGON ((407438.423 4292686.264, 407420.773 4...
34 5 DZA Algeria 12 Bouira 387 MEZDOUR Commune Commune None None None None POLYGON ((452784.132 4306053.836, 452773.782 4...
35 5 DZA Algeria 12 Bouira 388 OUED-EL-BERDI Commune Commune None None None None POLYGON ((444351.456 4326332.939, 444341.318 4...
36 5 DZA Algeria 12 Bouira 389 OULED-RACHED Commune Commune None None None None POLYGON ((444341.318 4326327.678, 444351.456 4...
37 5 DZA Algeria 12 Bouira 390 RAOURAOUA Commune Commune None None None None POLYGON ((396032.001 4329097.130, 396155.680 4...
38 5 DZA Algeria 12 Bouira 391 RIDANE Commune Commune None None None None POLYGON ((385453.090 4305955.631, 385272.083 4...
39 5 DZA Algeria 12 Bouira 392 SAHARIDJ Commune Commune None None None None POLYGON ((476714.708 4354724.728, 476383.056 4...
40 5 DZA Algeria 12 Bouira 393 SOUK-EL-KHEMIS Commune Commune None None None None POLYGON ((404434.394 4347814.163, 404346.465 4...
41 5 DZA Algeria 12 Bouira 394 SOUR-EL-GHOZLANE Commune Commune None None None None POLYGON ((408931.705 4328727.688, 408964.217 4...
42 5 DZA Algeria 12 Bouira 395 TAGHZOUT Commune Commune None None None None POLYGON ((438557.715 4363083.038, 438838.144 4...
43 5 DZA Algeria 12 Bouira 396 TAGUEDITE Commune Commune None None None None POLYGON ((448194.885 4281452.803, 448058.944 4...
44 5 DZA Algeria 12 Bouira 397 Z'BARBAR Commune Commune None None None None POLYGON ((396860.440 4360082.101, 396647.372 4...
In [3]:
path_2 ="./data/Population10.csv"
df = pd.read_csv(path_2)

df
Out[3]:
Commune Masculin Féminin Total Taux Commune_ar
0 Bouira 44950 43851 88801 1.7 اﻟﺒﻮﻳﺮة
1 El Asnam 6615 6597 13213 0.9 اﻷﺻﻨﺎم
2 Guerrouma 7398 7172 14570 0.5 ﻗﺮوﻣﺔ
3 Souk El Khemis 467 3935 83 0.0 ﺳﻮق-اﻟﺨﻤﻴﺲ
4 Kadiria 11268 1160 22327 2.3 اﻟﻘﺎدرﻳﺔ
5 ahnif 4876 4810 9685 0.6 اﻟﺤﺎﻧﻴﻒ
6 Dirrah 6864 6346 13209 0.6 دﻳﺮة
7 Ait Laaziz 7450 6980 14430 0.3 ﺁﻳﺖ-ﻟﻌﺰﻳﺰ
8 Taghzout 6636 6567 13203 1.0 ﺗﺎﻏﺰوت
9 Raouraoua 4278 4172 8450 1.6 راوراوة
10 Mezdour 5567 5480 1147 0.3 ﻣﺰدور
11 Haizer 8937 8782 17719 1.4 اﻟﺤﻴﺰر
12 Lakhdaria 30719 2927 59746 1.3 اﻷﺧﻀﺮﻳﺔ
13 Maala 2650 2646 5296 0.9 اﻟﻤﻌﻠﻤﺔ
14 El Hachimia 8791 8530 17322 2.6 اﻟﻬﺎﺷﻤﻴﺔ
15 Aomar 10508 1024 20532 0.0 أوﻋﻤﺮ
16 Chorfa 8237 7936 16173 0.9 اﻟﺸﺮﻓﺎء
17 Bordj Okhriss 5331 5137 10467 1.6 ﺑﺮج-أوﺧﺮﻳﺺ
18 El Adjiba 6325 6162 12486 0.8 اﻟﻌﺠﻴﺒﺔ
19 El Hakimia 1149 163 2212 0.0 اﻟﺤﺎآﻤﻴﺔ
20 El Khabouzia 391 340 6132 1.0 اﻟﺨﺒﻮزﻳﺔ
21 Ahl El Ksar 6703 6651 13354 0.8 أهﻞ_اﻟﻘﺼﺮ
22 Bouderbala 8846 8743 17589 0.5 ﺑﻮدرﺑﺎﻟﺔ
23 Z'barbar 1850 1918 3768 -1.8 زﺑﺮﺑﺮ
24 Ain El Hadjar 4659 4601 9260 1.5 ﻋﻴﻦ-اﻟﺤﺠﺎر
25 Djebahia 7971 7622 15592 0.7 ﺟﺒﺎﺣﻴﺔ
26 Aghbalou 9945 9571 19517 0.0 أﻏﺒﺎﻟﻮ
27 Taguedite 5350 5212 10562 0.3 ﺗﺎﻗﺪﻳﺖ
28 Ain Turk 499 3750 7849 1.4 ﻋﻴﻦ-اﻟﺘﺮك
29 Saharidj 4270 4252 8522 0.7 اﻟﺼﻬﺎرﻳﺞ
30 Dechmia 3802 3702 7504 0.1 اﻟﺪﺷﻤﻴﺔ
31 Ridane 1692 1576 3268 0.8 رﻳﺪان
32 Bechloul 5910 5865 11775 1.3 ﺑﺸﻠﻮل
33 Boukram 2778 2868 5647 -1.1 ﺑﻮآﺮوم
34 Ain Bessem 21592 2143 42635 1.5 ﻋﻴﻦ-ﺑﺴﺎم
35 Bir Ghbalou 5646 5370 1116 1.9 ﺑﺌﺮ-ﻏﺒﺎﻟﻮ
36 M'chedallah 12426 11981 24406 1.3 ﻣﺸﺪااﷲ
37 Sour El Ghozlane 25360 24760 50120 1.8 ﺻﻮر-اﻟﻐﺰﻻن
38 Maamoura 1858 1794 3652 0.2 اﻟﻤﻌﻤﻮرة
39 Ouled Rached 4721 4590 9311 0.9 أوﻻد-راﺷﺪ
40 Ain Laloui 3557 3182 6738 1.4 ﻋﻴﻦ-اﻟﻌﻠﻮى
41 Hadjera Zerga 1887 1786 3672 1.4 اﻟﺤﺠﺮة-اﻟﺰرﻗﺎء
42 Ath Mansour 5117 4959 1077 0.8 ﺁث-ﻣﻨﺼﻮر
43 El Mokrani 1942 219 3961 -2.1 اﻟﻤﻘﺮاﻧﻲ
44 Oued El Berdi 5510 5257 10767 1.6 وادى-اﻟﺒﺮدي

Normalisation des données¶

  • Mettre les noms de communes en majuscule
  • Remplacer le caractère blanc par un tiret '-'
  • Renommer la colomnne Communes par NAME_2
In [4]:
df['Commune']=df['Commune'].str.upper()
In [5]:
df['Commune']=df['Commune'].str.replace(' ', '-')
In [6]:
df.rename(columns={"Commune": "NAME_2"}, inplace=True)
  • Sauvegarder le dataframe normalisé
In [7]:
df.to_csv('path_2', index=False) 

Fusion¶

Maintenant, après avoir normaliser on peut Fusionner la geodataframe (frontière) avec la dataframe (Population)

Question on dit un dataframe où une dataframe?

In [8]:
merged = pd.merge(left=gdf, right=df, how="left", on="NAME_2")
merged
Out[8]:
ID_0 ISO NAME_0 ID_1 NAME_1 ID_2 NAME_2 TYPE_2 ENGTYPE_2 X Y Population superficie geometry Masculin Féminin Total Taux Commune_ar
0 5 DZA Algeria 12 Bouira 353 AGHBALOU Commune Commune None None None None POLYGON ((478679.140 4354598.121, 478546.437 4... 9945 9571 19517 0.0 أﻏﺒﺎﻟﻮ
1 5 DZA Algeria 12 Bouira 354 AHL-EL-KSAR Commune Commune None None None None POLYGON ((458096.559 4339404.491, 458085.518 4... 6703 6651 13354 0.8 أهﻞ_اﻟﻘﺼﺮ
2 5 DZA Algeria 12 Bouira 355 AHNIF Commune Commune None None None None POLYGON ((473835.421 4332764.866, 473715.086 4... 4876 4810 9685 0.6 اﻟﺤﺎﻧﻴﻒ
3 5 DZA Algeria 12 Bouira 356 AIN-BESSEM Commune Commune None None None None POLYGON ((410218.793 4335155.776, 410175.479 4... 21592 2143 42635 1.5 ﻋﻴﻦ-ﺑﺴﺎم
4 5 DZA Algeria 12 Bouira 357 AIN-EL-HADJAR Commune Commune None None None None POLYGON ((426730.571 4349243.480, 426751.618 4... 4659 4601 9260 1.5 ﻋﻴﻦ-اﻟﺤﺠﺎر
5 5 DZA Algeria 12 Bouira 358 AIN-LALOUI Commune Commune None None None None POLYGON ((414504.920 4348625.545, 414544.439 4... 3557 3182 6738 1.4 ﻋﻴﻦ-اﻟﻌﻠﻮى
6 5 DZA Algeria 12 Bouira 359 AIN-TURK Commune Commune None None None None POLYGON ((428803.448 4359789.178, 428789.328 4... 499 3750 7849 1.4 ﻋﻴﻦ-اﻟﺘﺮك
7 5 DZA Algeria 12 Bouira 360 AIT-LAAZIZ Commune Commune None None None None POLYGON ((438557.715 4363083.038, 438550.470 4... 7450 6980 14430 0.3 ﺁﻳﺖ-ﻟﻌﺰﻳﺰ
8 5 DZA Algeria 12 Bouira 361 AOMAR Commune Commune None None None None POLYGON ((427249.759 4363316.919, 427215.814 4... 10508 1024 20532 0.0 أوﻋﻤﺮ
9 5 DZA Algeria 12 Bouira 362 ATH-MANSOUR Commune Commune None None None None POLYGON ((476926.874 4347296.472, 476937.331 4... 5117 4959 1077 0.8 ﺁث-ﻣﻨﺼﻮر
10 5 DZA Algeria 12 Bouira 363 BECHLOUL Commune Commune None None None None POLYGON ((448654.516 4340431.766, 448587.580 4... 5910 5865 11775 1.3 ﺑﺸﻠﻮل
11 5 DZA Algeria 12 Bouira 364 BIR-GHBALOU Commune Commune None None None None POLYGON ((405529.010 4338312.000, 405500.293 4... 5646 5370 1116 1.9 ﺑﺌﺮ-ﻏﺒﺎﻟﻮ
12 5 DZA Algeria 12 Bouira 365 BORDJ-OKHRISS Commune Commune None None None None POLYGON ((426167.406 4307012.819, 426155.834 4... 5331 5137 10467 1.6 ﺑﺮج-أوﺧﺮﻳﺺ
13 5 DZA Algeria 12 Bouira 366 BOUDERBALA Commune Commune None None None None POLYGON ((392844.922 4384172.391, 393300.784 4... 8846 8743 17589 0.5 ﺑﻮدرﺑﺎﻟﺔ
14 5 DZA Algeria 12 Bouira 367 BOUIRA Chef-Lieu-Wilaya Chef-Lieu-Wilaya None None None None POLYGON ((426730.571 4349243.480, 426779.672 4... 44950 43851 88801 1.7 اﻟﺒﻮﻳﺮة
15 5 DZA Algeria 12 Bouira 368 BOUKRAM Commune Commune None None None None POLYGON ((367367.903 4376059.806, 367446.384 4... 2778 2868 5647 -1.1 ﺑﻮآﺮوم
16 5 DZA Algeria 12 Bouira 369 CHORFA Commune Commune None None None None POLYGON ((482711.458 4348736.265, 482508.635 4... 8237 7936 16173 0.9 اﻟﺸﺮﻓﺎء
17 5 DZA Algeria 12 Bouira 370 DECHMIA Commune Commune None None None None POLYGON ((408931.705 4328727.688, 408930.484 4... 3802 3702 7504 0.1 اﻟﺪﺷﻤﻴﺔ
18 5 DZA Algeria 12 Bouira 371 DIRRAH Commune Commune None None None None POLYGON ((425063.899 4306334.275, 424907.601 4... 6864 6346 13209 0.6 دﻳﺮة
19 5 DZA Algeria 12 Bouira 372 DJEBAHIA Commune Commune None None None None POLYGON ((420478.102 4359749.067, 420458.276 4... 7971 7622 15592 0.7 ﺟﺒﺎﺣﻴﺔ
20 5 DZA Algeria 12 Bouira 373 EL-ADJIBA Commune Commune None None None None POLYGON ((460499.867 4340479.707, 460328.679 4... 6325 6162 12486 0.8 اﻟﻌﺠﻴﺒﺔ
21 5 DZA Algeria 12 Bouira 374 EL-ASNAM Commune Commune None None None None POLYGON ((448654.516 4340431.766, 448578.928 4... 6615 6597 13213 0.9 اﻷﺻﻨﺎم
22 5 DZA Algeria 12 Bouira 375 EL-HACHIMIA Commune Commune None None None None POLYGON ((422183.497 4320581.606, 422180.949 4... 8791 8530 17322 2.6 اﻟﻬﺎﺷﻤﻴﺔ
23 5 DZA Algeria 12 Bouira 376 EL-HAKIMIA Commune Commune None None None None POLYGON ((426167.406 4307012.819, 426180.092 4... 1149 163 2212 0.0 اﻟﺤﺎآﻤﻴﺔ
24 5 DZA Algeria 12 Bouira 377 EL-KHABOUZIA Commune Commune None None None None POLYGON ((406837.782 4338739.186, 406761.875 4... 391 340 6132 1.0 اﻟﺨﺒﻮزﻳﺔ
25 5 DZA Algeria 12 Bouira 378 EL-MOKRANI Commune Commune None None None None POLYGON ((396860.440 4360082.101, 396878.913 4... 1942 219 3961 -2.1 اﻟﻤﻘﺮاﻧﻲ
26 5 DZA Algeria 12 Bouira 379 GUERROUMA Commune Commune None None None None POLYGON ((389988.008 4371789.183, 389836.169 4... 7398 7172 14570 0.5 ﻗﺮوﻣﺔ
27 5 DZA Algeria 12 Bouira 380 HADJERA-ZERGA Commune Commune None None None None POLYGON ((426299.313 4306507.583, 426368.239 4... 1887 1786 3672 1.4 اﻟﺤﺠﺮة-اﻟﺰرﻗﺎء
28 5 DZA Algeria 12 Bouira 381 HAIZER Commune Commune None None None None POLYGON ((438349.557 4351516.227, 438372.700 4... 8937 8782 17719 1.4 اﻟﺤﻴﺰر
29 5 DZA Algeria 12 Bouira 382 KADIRIA Commune Commune None None None None POLYGON ((405093.292 4365529.805, 405058.232 4... 11268 1160 22327 2.3 اﻟﻘﺎدرﻳﺔ
30 5 DZA Algeria 12 Bouira 383 LAKHDARIA Commune Commune None None None None POLYGON ((400237.763 4373757.549, 400226.191 4... 30719 2927 59746 1.3 اﻷﺧﻀﺮﻳﺔ
31 5 DZA Algeria 12 Bouira 384 M'CHEDALLAH Commune Commune None None None None POLYGON ((464933.002 4354447.250, 465100.739 4... 12426 11981 24406 1.3 ﻣﺸﺪااﷲ
32 5 DZA Algeria 12 Bouira 385 MAALA Commune Commune None None None None POLYGON ((397325.432 4361620.207, 397313.277 4... 2650 2646 5296 0.9 اﻟﻤﻌﻠﻤﺔ
33 5 DZA Algeria 12 Bouira 386 MAAMOURA Commune Commune None None None None POLYGON ((407438.423 4292686.264, 407420.773 4... 1858 1794 3652 0.2 اﻟﻤﻌﻤﻮرة
34 5 DZA Algeria 12 Bouira 387 MEZDOUR Commune Commune None None None None POLYGON ((452784.132 4306053.836, 452773.782 4... 5567 5480 1147 0.3 ﻣﺰدور
35 5 DZA Algeria 12 Bouira 388 OUED-EL-BERDI Commune Commune None None None None POLYGON ((444351.456 4326332.939, 444341.318 4... 5510 5257 10767 1.6 وادى-اﻟﺒﺮدي
36 5 DZA Algeria 12 Bouira 389 OULED-RACHED Commune Commune None None None None POLYGON ((444341.318 4326327.678, 444351.456 4... 4721 4590 9311 0.9 أوﻻد-راﺷﺪ
37 5 DZA Algeria 12 Bouira 390 RAOURAOUA Commune Commune None None None None POLYGON ((396032.001 4329097.130, 396155.680 4... 4278 4172 8450 1.6 راوراوة
38 5 DZA Algeria 12 Bouira 391 RIDANE Commune Commune None None None None POLYGON ((385453.090 4305955.631, 385272.083 4... 1692 1576 3268 0.8 رﻳﺪان
39 5 DZA Algeria 12 Bouira 392 SAHARIDJ Commune Commune None None None None POLYGON ((476714.708 4354724.728, 476383.056 4... 4270 4252 8522 0.7 اﻟﺼﻬﺎرﻳﺞ
40 5 DZA Algeria 12 Bouira 393 SOUK-EL-KHEMIS Commune Commune None None None None POLYGON ((404434.394 4347814.163, 404346.465 4... 467 3935 83 0.0 ﺳﻮق-اﻟﺨﻤﻴﺲ
41 5 DZA Algeria 12 Bouira 394 SOUR-EL-GHOZLANE Commune Commune None None None None POLYGON ((408931.705 4328727.688, 408964.217 4... 25360 24760 50120 1.8 ﺻﻮر-اﻟﻐﺰﻻن
42 5 DZA Algeria 12 Bouira 395 TAGHZOUT Commune Commune None None None None POLYGON ((438557.715 4363083.038, 438838.144 4... 6636 6567 13203 1.0 ﺗﺎﻏﺰوت
43 5 DZA Algeria 12 Bouira 396 TAGUEDITE Commune Commune None None None None POLYGON ((448194.885 4281452.803, 448058.944 4... 5350 5212 10562 0.3 ﺗﺎﻗﺪﻳﺖ
44 5 DZA Algeria 12 Bouira 397 Z'BARBAR Commune Commune None None None None POLYGON ((396860.440 4360082.101, 396647.372 4... 1850 1918 3768 -1.8 زﺑﺮﺑﺮ

Cartes choroplèthes¶

GeoPandas facilite la création de cartes Choropleth (cartes où la couleur de chaque forme est basée sur la valeur d'une variable associée). Utilisez simplement la commande plot avec l'argument de colonne défini sur la colonne dont vous souhaitez utiliser les valeurs pour attribuer des couleurs.

In [9]:
 # Plot by population

merged.plot(column="Total");
No description has been provided for this image

Créer une légende¶

In [10]:
merged.plot(
    column="Total",
    legend=True,
    legend_kwds={"label": "Population 2008", "orientation": "horizontal"},
);
No description has been provided for this image

Toutefois, l’apparence par défaut des axes de légende et de tracé n’est peut-être pas souhaitable. On peut définir les axes de tracé (avec ax) et les axes de légende (avec cax), puis les transmettre à l'appel plot(). L'exemple suivant utilise mpl_toolkits pour aligner horizontalement les axes du tracé et les axes de la légende et modifier la largeur :

In [11]:
import matplotlib.pyplot as plt

from mpl_toolkits.axes_grid1 import make_axes_locatable

fig, ax = plt.subplots(1, 1)

divider = make_axes_locatable(ax)

cax = divider.append_axes("bottom", size="5%", pad=0.1)

merged.plot(
    column="Total",
    ax=ax,
    legend=True,
    cax=cax,
    legend_kwds={"label": "Population in 2008", "orientation": "horizontal"},
);
No description has been provided for this image

Choisir les couleurs¶

Vous pouvez également modifier les couleurs utilisées par plot() avec l'option cmap. Pour une liste complète des palettes de couleurs, consultez Choisir des palettes de couleurs dans Matplotlib.

In [12]:
merged.plot(column='Total', cmap='OrRd');
No description has been provided for this image

Attention!¶

Une erreur fréquente lors de la production de cartes choroplèthes consiste à encoder des valeurs de données brutes (comme la population) plutôt que d'utiliser des valeurs normalisées (en calculant la population par kilomètre carré par exemple) pour produire une carte de densité.

exercice:¶

Créer une carte de densité selon l'equation suivante:

\begin{equation*} Densité = \frac{Population}{superficie} \end{equation*}

Tout d'abord il faut calculer la colomne Superficie (voir la section: Zone de mesure )

In [14]:
merged["Densité"]=merged["Total"]/merged.area
In [26]:
fig, ax = plt.subplots(1, 1)

divider = make_axes_locatable(ax)

cax = divider.append_axes("bottom", size="5%", pad=0.1)

merged.plot(
    column="Densité",
    ax=ax,
    legend=True,
    cax=cax,
    cmap="RdYlBu_r",
    legend_kwds={"label": "Population in 2008", "orientation": "horizontal"},
);
No description has been provided for this image