How to Plot a World Map Using Python and GeoPandas

Lately I’ve been exploring EM-DAT, an international database of approximately 26,000 major natural disasters from the year 1900 to present day.

During my exploration, I’ve wanted a way to:

  1. Use Python and Pandas to process the EM-DAT dataset
  2. Analyze natural disasters on a per-country basis
  3. Plot a map of the world
  4. Overlay a heatmap of the number of natural disasters for each country, thereby giving a visual representation of where in the world natural disasters occur

I’ve already covered a basic exploration of the EM-DAT dataset in the following articles:

  1. Getting Started with the International Disaster Database (EM-DAT) using Python and Pandas
  2. Exploring Natural Disaster Types in the EM-DAT Dataset with Python and Pandas
  3. Decoding the EM-DAT Natural Disaster Dataset Hierarchy

The next step is to move on to plotting a map of the world with Python.

My explorations led me to a fantastic article by Jonathan Cutrer where he demonstrated how to use GeoPandas library to create a map of the United States.

I’ve taken his implementation and modified it to plot a map of the world.

This article covers plotting a basic world map with Python and GeoPandas.

I’ll then extend this implementation in future experiments.

Download the code

Plotting a map of the world with Python and GeoPandas

The easiest way to plot a map of the world with Python is to use GeoPandas:

# import the necessary packages
import matplotlib.patches as mpatches
import matplotlib.pyplot as plt
import seaborn as sns
import geopandas as gpd

# load the low resolution world map
world = gpd.read_file(gpd.datasets.get_path("naturalearth_lowres"))

GeoPandas ships with a built-in dataset named naturalearth_lowres (meaning “Natural Earth - Low Resolution”, which is effectively just a Pandas dataframe:

pop_estcontinentnameiso_a3gdp_md_estgeometry
0889953.0OceaniaFijiFJI5496MULTIPOLYGON (((180.00000 -16.06713, 180.00000 -16.55522, 179.36414 -16.80135, 178.72506 -17.01204, 178.59684 -16.63915, 179.09661 -16.43398, 179.41351 -16.37905, 180.00000 -16.06713)), ((178.12557 -17.50481, 178.37360 -17.33992, 178.71806 -17.62846, 178.55271 -18.15059, 177.93266 -18.28799, 177.38146 -18.16432, 177.28504 -17.72465, 177.67087 -17.38114, 178.12557 -17.50481)), ((-179.79332 -16.02088, -179.91737 -16.50178, -180.00000 -16.55522, -180.00000 -16.06713, -179.79332 -16.02088)))
158005463.0AfricaTanzaniaTZA63177POLYGON ((33.90371 -0.95000, 34.07262 -1.05982, 37.69869 -3.09699, 37.76690 -3.67712, 39.20222 -4.67677, 38.74054 -5.90895, 38.79977 -6.47566, 39.44000 -6.84000, 39.47000 -7.10000, 39.19469 -7.70390, 39.25203 -8.00781, 39.18652 -8.48551, 39.53574 -9.11237, 39.94960 -10.09840, 40.31659 -10.31710, 40.31659 -10.31710, 39.52100 -10.89688, 38.42756 -11.28520, 37.82764 -11.26879, 37.47129 -11.56876, 36.77515 -11.59454, 36.51408 -11.72094, 35.31240 -11.43915, 34.55999 -11.52002, 34.28000 -10.16000, 33.94084 -9.69367, 33.73972 -9.41715, 32.75938 -9.23060, 32.19186 -8.93036, 31.55635 -8.76205, 31.15775 -8.59458, 30.74001 -8.34001, 30.74002 -8.34001, 30.20000 -7.07998, 29.62003 -6.52002, 29.41999 -5.94000, 29.51999 -5.41998, 29.34000 -4.49998, 29.75351 -4.45239, 30.11632 -4.09012, 30.50554 -3.56858, 30.75224 -3.35931, 30.74301 -3.03431, 30.52766 -2.80762, 30.46967 -2.41385, 30.46967 -2.41383, 30.75831 -2.28725, 30.81613 -1.69891, 30.41910 -1.13466, 30.76986 -1.01455, 31.86617 -1.02736, 33.90371 -0.95000))
2603253.0AfricaW. SaharaESH907POLYGON ((-8.66559 27.65643, -8.66512 27.58948, -8.68440 27.39574, -8.68729 25.88106, -11.96942 25.93335, -11.93722 23.37459, -12.87422 23.28483, -13.11875 22.77122, -12.92910 21.32707, -16.84519 21.33332, -17.06342 20.99975, -17.02043 21.42231, -17.00296 21.42073, -14.75095 21.50060, -14.63083 21.86094, -14.22117 22.31016, -13.89111 23.69101, -12.50096 24.77012, -12.03076 26.03087, -11.71822 26.10409, -11.39255 26.88342, -10.55126 26.99081, -10.18942 26.86094, -9.73534 26.86094, -9.41304 27.08848, -8.79488 27.12070, -8.81783 27.65643, -8.66559 27.65643))
337589262.0North AmericaCanadaCAN1736425MULTIPOLYGON (((-122.84000 49.00000, -122.97421 49.00254, -124.91024 49.98456, -125.62461 50.41656, -127.43561 50.83061, -127.99276 51.71583, -127.85032 52.32961, -129.12979 52.75538, -129.30523 53.56159, -130.51497 54.28757, -130.53611 54.80275, -130.53611 54.80278, -129.98000 55.28500, -130.00778 55.91583, -131.70781 56.55212, -132.73042 57.69289, -133.35556 58.41028, -134.27111 58.86111, -134.94500 59.27056, -135.47583 59.78778, -136.47972 59.46389, -137.45250 58.90500, -138.34089 59.56211, -139.03900 60.00000, -140.01300 60.27682, -140.99778 60.30639, -140.99250 66.00003, -140.98600 69.71200, -140.98599 69.71200, -139.12052 69.47102, -137.54636 68.99002, -136.50358 68.89804, -135.62576 69.31512, -134.41464 69.62743, -132.92925 69.50534, -131.43136 69.94451, -129.79471 70.19369, -129.10773 69.77927, -128.36156 70.01286, -128.13817 70.48384, -127.44712 70.37721, -125.75632 69.48058, -124.42483 70.15840, -124.28968 69.39969, -123.06108 69.56372, -122.68350 69.85553, -121.47226 69.79778, -119.94288 69.37786, -117.60268 69.01128, -116.22643 68.84151, -115.24690 68.90591, -113.89794 68.39890, -115.30489 67.90261, -113.49727 67.68815, -110.79800 67.80612, -109.94619 67.98104, -108.88020 67.38144, -107.79239 67.88736, -108.81299 68.31164, -108.16721 68.65392, -106.95000 68.70000, -106.15000 68.80000, -105.34282 68.56122, -104.33791 68.01800, -103.22115 68.09775, -101.45433 67.64689, -99.90195 67.80566, -98.44320 67.78165, -98.55860 68.40394, -97.66948 68.57864, -96.11991 68.23939, -96.12588 67.29338, -95.48943 68.09070, -94.68500 68.06383, -94.23282 69.06903, -95.30408 69.68571, -96.47131 70.08976, -96.39115 71.19482, -95.20880 71.92053, -93.88997 71.76015, -92.87818 71.31869, -91.51964 70.19129, -92.40692 69.69997, -90.54710 69.49766, -90.55151 68.47499, -89.21515 69.25873, -88.01966 68.61508, -88.31749 67.87338, -87.35017 67.19872, -86.30607 67.92146, -85.57664 68.78456, -85.52197 69.88211, -84.10081 69.80539, -82.62258 69.65826, -81.28043 69.16202, -81.22020 68.66567, -81.96436 68.13253, -81.25928 67.59716, -81.38653 67.11078, -83.34456 66.41154, -84.73542 66.25730, -85.76943 66.55833, -86.06760 66.05625, -87.03143 65.21297, -87.32324 64.77563, -88.48296 64.09897, -89.91444 64.03273, -90.70398 63.61017, -90.77004 62.96021, -91.93342 62.83508, -93.15698 62.02469, -94.24153 60.89865, -94.62931 60.11021, -94.68460 58.94882, -93.21502 58.78212, -92.76462 57.84571, -92.29703 57.08709, -90.89769 57.28468, -89.03953 56.85172, -88.03978 56.47162, -87.32421 55.99914, -86.07121 55.72383, -85.01181 55.30260, -83.36055 55.24489, -82.27285 55.14832, -82.43620 54.28227, -82.12502 53.27703, -81.40075 52.15788, -79.91289 51.20842, -79.14301 51.53393, -78.60191 52.56208, -79.12421 54.14145, -79.82958 54.66772, -78.22874 55.13645, -77.09560 55.83741, -76.54137 56.53423, -76.62319 57.20263, -77.30226 58.05209, -78.51688 58.80458, -77.33676 59.85261, -77.77272 60.75788, -78.10687 62.31964, -77.41067 62.55053, -75.69621 62.27840, -74.66820 62.18111, -73.83988 62.44380, -72.90853 62.10507, -71.67708 61.52535, -71.37369 61.13717, -69.59042 61.06141, -69.62033 60.22125, -69.28790 58.95736, -68.37455 58.80106, -67.64976 58.21206, -66.20178 58.76731, -65.24517 59.87071, -64.58352 60.33558, -63.80475 59.44260, -62.50236 58.16708, -61.39655 56.96745, -61.79866 56.33945, -60.46853 55.77548, -59.56962 55.20407, -57.97508 54.94549, -57.33320 54.62650, -56.93689 53.78032, -56.15811 53.64749, -55.75632 53.27036, -55.68338 52.14664, -56.40916 51.77070, -57.12691 51.41972, -58.77482 51.06430, -60.03309 50.24277, -61.72366 50.08046, -63.86251 50.29099, -65.36331 50.29820, -66.39905 50.22897, -67.23631 49.51156, -68.51114 49.06836, -69.95362 47.74488, -71.10458 46.82171, -70.25522 46.98606, -68.65000 48.30000, -66.55243 49.13310, -65.05626 49.23278, -64.17099 48.74248, -65.11545 48.07085, -64.79854 46.99297, -64.47219 46.23849, -63.17329 45.73902, -61.52072 45.88377, -60.51815 47.00793, -60.44860 46.28264, -59.80287 45.92040, -61.03988 45.26525, -63.25471 44.67014, -64.24656 44.26553, -65.36406 43.54523, -66.12340 43.61867, -66.16173 44.46512, -64.42549 45.29204, -66.02605 45.25931, -67.13741 45.13753, -67.79134 45.70281, -67.79046 47.06636, -68.23444 47.35486, -68.90500 47.18500, -69.23722 47.44778, -69.99997 46.69307, -70.30500 45.91500, -70.66000 45.46000, -71.08482 45.30524, -71.40500 45.25500, -71.50506 45.00820, -73.34783 45.00738, -74.86700 45.00048, -75.31821 44.81645, -76.37500 44.09631, -76.50000 44.01846, -76.82003 43.62878, -77.73789 43.62906, -78.72028 43.62509, -79.17167 43.46634, -79.01000 43.27000, -78.92000 42.96500, -78.93936 42.86361, -80.24745 42.36620, -81.27775 42.20903, -82.43928 41.67511, -82.69009 41.67511, -83.02981 41.83280, -83.14200 41.97568, -83.12000 42.08000, -82.90000 42.43000, -82.43000 42.98000, -82.13764 43.57109, -82.33776 44.44000, -82.55092 45.34752, -83.59285 45.81689, -83.46955 45.99469, -83.61613 46.11693, -83.89077 46.11693, -84.09185 46.27542, -84.14212 46.51223, -84.33670 46.40877, -84.60490 46.43960, -84.54375 46.53868, -84.77924 46.63710, -84.87608 46.90008, -85.65236 47.22022, -86.46199 47.55334, -87.43979 47.94000, -88.37811 48.30292, -89.27292 48.01981, -89.60000 48.01000, -90.83000 48.27000, -91.64000 48.14000, -92.61000 48.45000, -93.63087 48.60926, -94.32914 48.67074, -94.64000 48.84000, -94.81758 49.38905, -95.15609 49.38425, -95.15907 49.00000, -97.22872 49.00070, -100.65000 49.00000, -104.04826 48.99986, -107.05000 49.00000, -110.05000 49.00000, -113.00000 49.00000, -116.04818 49.00000, -117.03121 49.00000, -120.00000 49.00000, -122.84000 49.00000)), ((-83.99367 62.45280, -83.25048 62.91409, -81.87699 62.90458, -81.89825 62.71080, -83.06857 62.15922, -83.77462 62.18231, -83.99367 62.45280)), ((-79.77583 72.80290, -80.87610 73.33318, -80.83389 73.69318, -80.35306 73.75972, -78.06444 73.65193, -76.34000 73.10268, -76.25140 72.82639, -77.31444 72.85555, -78.39167 72.87666, -79.48625 72.74220, -79.77583 72.80290)), ((-80.31539 62.08557, -79.92939 62.38560, -79.52002 62.36371, -79.26582 62.15867, -79.65752 61.63308, -80.09956 61.71810, -80.36215 62.01649, -80.31539 62.08557)), ((-93.61276 74.98000, -94.15691 74.59235, -95.60868 74.66686, -96.82093 74.92762, -96.28859 75.37783, -94.85082 75.64722, -93.97775 75.29649, -93.61276 74.98000)), ((-93.84000 77.52000, -94.29561 77.49134, -96.16965 77.55511, -96.43630 77.83463, -94.42258 77.82000, -93.72066 77.63433, -93.84000 77.52000)), ((-96.75440 78.76581, -95.55928 78.41831, -95.83029 78.05694, -97.30984 77.85060, -98.12429 78.08286, -98.55287 78.45811, -98.63198 78.87193, -97.33723 78.83198, -96.75440 78.76581)), ((-88.15035 74.39231, -89.76472 74.51556, -92.42244 74.83776, -92.76829 75.38682, -92.88991 75.88266, -93.89382 76.31924, -95.96246 76.44138, -97.12138 76.75108, -96.74512 77.16139, -94.68409 77.09788, -93.57392 76.77630, -91.60502 76.77852, -90.74185 76.44960, -90.96966 76.07401, -89.82224 75.84777, -89.18708 75.61017, -87.83828 75.56619, -86.37919 75.48242, -84.78963 75.69920, -82.75344 75.78432, -81.12853 75.71398, -80.05751 75.33685, -79.83393 74.92313, -80.45777 74.65730, -81.94884 74.44246, -83.22889 74.56403, -86.09745 74.41003, -88.15035 74.39231)), ((-111.26444 78.15296, -109.85445 77.99632, -110.18694 77.69701, -112.05119 77.40923, -113.53428 77.73221, -112.72459 78.05105, -111.26444 78.15296)), ((-110.96366 78.80444, -109.66315 78.60197, -110.88131 78.40692, -112.54209 78.40790, -112.52589 78.55055, -111.50001 78.84999, -110.96366 78.80444)), ((-55.60022 51.31707, -56.13404 50.68701, -56.79588 49.81231, -56.14311 50.15012, -55.47149 49.93582, -55.82240 49.58713, -54.93514 49.31301, -54.47378 49.55669, -53.47655 49.24914, -53.78601 48.51678, -53.08613 48.68780, -52.95865 48.15716, -52.64810 47.53555, -53.06916 46.65550, -53.52146 46.61829, -54.17894 46.80707, -53.96187 47.62521, -54.24048 47.75228, -55.40077 46.88499, -55.99748 46.91972, -55.29122 47.38956, -56.25080 47.63255, -57.32523 47.57281, -59.26602 47.60335, -59.41949 47.89945, -58.79659 48.25153, -59.23162 48.52319, -58.39180 49.12558, -57.35869 50.71827, -56.73865 51.28744, -55.87098 51.63209, -55.40697 51.58827, -55.60022 51.31707)), ((-83.88263 65.10962, -82.78758 64.76669, -81.64201 64.45514, -81.55344 63.97961, -80.81736 64.05749, -80.10345 63.72598, -80.99102 63.41125, -82.54718 63.65172, -83.10880 64.10188, -84.10042 63.56971, -85.52340 63.05238, -85.86677 63.63725, -87.22198 63.54124, -86.35276 64.03583, -86.22489 64.82292, -85.88385 65.73878, -85.16131 65.65728, -84.97576 65.21752, -84.46401 65.37177, -83.88263 65.10962)), ((-78.77064 72.35217, -77.82462 72.74962, -75.60584 72.24368, -74.22862 71.76714, -74.09914 71.33084, -72.24223 71.55692, -71.20002 70.92001, -68.78605 70.52502, -67.91497 70.12195, -66.96903 69.18609, -68.80512 68.72020, -66.44987 68.06716, -64.86231 67.84754, -63.42493 66.92847, -61.85198 66.86212, -62.16318 66.16025, -63.91844 64.99867, -65.14886 65.42603, -66.72122 66.38804, -68.01502 66.26273, -68.14129 65.68979, -67.08965 65.10846, -65.73208 64.64841, -65.32017 64.38274, -64.66941 63.39293, -65.01380 62.67419, -66.27504 62.94510, -68.78319 63.74567, -67.36968 62.88397, -66.32830 62.28007, -66.16557 61.93090, -68.87737 62.33015, -71.02344 62.91071, -72.23538 63.39784, -71.88628 63.67999, -73.37831 64.19396, -74.83442 64.67908, -74.81850 64.38909, -77.70998 64.22954, -78.55595 64.57291, -77.89728 65.30919, -76.01827 65.32697, -73.95980 65.45476, -74.29388 65.81177, -73.94491 66.31058, -72.65117 67.28458, -72.92606 67.72693, -73.31162 68.06944, -74.84331 68.55463, -76.86910 68.89474, -76.22865 69.14777, -77.28737 69.76954, -78.16863 69.82649, -78.95724 70.16688, -79.49246 69.87181, -81.30547 69.74319, -84.94471 69.96663, -87.06000 70.26000, -88.68171 70.41074, -89.51342 70.76204, -88.46772 71.21819, -89.88815 71.22255, -90.20516 72.23507, -89.43658 73.12946, -88.40824 73.53789, -85.82615 73.80382, -86.56218 73.15745, -85.77437 72.53413, -84.85011 73.34028, -82.31559 73.75095, -80.60009 72.71654, -80.74894 72.06191, -78.77064 72.35217)), ((-94.50366 74.13491, -92.42001 74.10003, -90.50979 73.85673, -92.00397 72.96624, -93.19630 72.77199, -94.26905 72.02460, -95.40986 72.06188, -96.03375 72.94028, -96.01827 73.43743, -95.49579 73.86242, -94.50366 74.13491)), ((-122.85492 76.11654, -122.85493 76.11654, -121.15754 76.86451, -119.10394 77.51222, -117.57013 77.49832, -116.19859 77.64529, -116.33581 76.87696, -117.10605 76.53003, -118.04041 76.48117, -119.89932 76.05321, -121.50000 75.90002, -122.85492 76.11654)), ((-132.71001 54.04001, -131.74999 54.12000, -132.04948 52.98462, -131.17904 52.18043, -131.57783 52.18237, -132.18043 52.63971, -132.54999 53.10001, -133.05461 53.41147, -133.23966 53.85108, -133.18000 54.16998, -132.71001 54.04001)), ((-105.49229 79.30159, -103.52928 79.16535, -100.82516 78.80046, -100.06019 78.32475, -99.67094 77.90754, -101.30394 78.01898, -102.94981 78.34323, -105.17613 78.38033, -104.21043 78.67742, -105.41958 78.91834, -105.49229 79.30159)), ((-123.51000 48.51001, -124.01289 48.37085, -125.65501 48.82500, -125.95499 49.18000, -126.85000 49.53000, -127.02999 49.81500, -128.05934 49.99496, -128.44458 50.53914, -128.35841 50.77065, -127.30858 50.55257, -126.69500 50.40090, -125.75501 50.29502, -125.41500 49.95000, -124.92077 49.47527, -123.92251 49.06248, -123.51000 48.51001)), ((-121.53788 74.44893, -120.10978 74.24135, -117.55564 74.18577, -116.58442 73.89607, -115.51081 73.47519, -116.76794 73.22292, -119.22000 72.52000, -120.46000 71.82000, -120.46000 71.38360, -123.09219 70.90164, -123.62000 71.34000, -125.92895 71.86869, -125.50000 72.29226, -124.80729 73.02256, -123.94000 73.68000, -124.91775 74.29275, -121.53788 74.44893)), ((-107.81943 75.84552, -106.92893 76.01282, -105.88100 75.96940, -105.70498 75.47951, -106.31347 75.00527, -109.70000 74.85000, -112.22307 74.41696, -113.74381 74.39427, -113.87135 74.72029, -111.79421 75.16250, -116.31221 75.04343, -117.71040 75.22220, -116.34602 76.19903, -115.40487 76.47887, -112.59056 76.14134, -110.81422 75.54919, -109.06710 75.47321, -110.49726 76.42982, -109.58110 76.79417, -108.54859 76.67832, -108.21141 76.20168, -107.81943 75.84552)), ((-106.52259 73.07601, -105.40246 72.67259, -104.77484 71.69840, -104.46476 70.99297, -102.78537 70.49776, -100.98078 70.02432, -101.08929 69.58447, -102.73116 69.50402, -102.09329 69.11962, -102.43024 68.75282, -104.24000 68.91000, -105.96000 69.18000, -107.12254 69.11922, -109.00000 68.78000, -111.53415 68.63006, -113.31320 68.53554, -113.85496 69.00744, -115.22000 69.28000, -116.10794 69.16821, -117.34000 69.96000, -116.67473 70.06655, -115.13112 70.23730, -113.72141 70.19237, -112.41610 70.36638, -114.35000 70.60000, -116.48684 70.52045, -117.90480 70.54056, -118.43238 70.90920, -116.11311 71.30918, -117.65568 71.29520, -119.40199 71.55859, -118.56267 72.30785, -117.86642 72.70594, -115.18909 73.31459, -114.16717 73.12145, -114.66634 72.65277, -112.44102 72.95540, -111.05039 72.45040, -109.92035 72.96113, -109.00654 72.63335, -108.18835 71.65089, -107.68599 72.06548, -108.39639 73.08953, -107.51645 73.23598, -106.52259 73.07601)), ((-100.43836 72.70588, -101.54000 73.36000, -100.35642 73.84389, -99.16387 73.63339, -97.38000 73.76000, -97.12000 73.47000, -98.05359 72.99052, -96.54000 72.56000, -96.72000 71.66000, -98.35966 71.27285, -99.32286 71.35639, -100.01482 71.73827, -102.50000 72.51000, -102.48000 72.83000, -100.43836 72.70588)), ((-106.60000 73.60000, -105.26000 73.64000, -104.50000 73.42000, -105.38000 72.76000, -106.94000 73.46000, -106.60000 73.60000)), ((-98.50000 76.72000, -97.73559 76.25656, -97.70442 75.74344, -98.16000 75.00000, -99.80874 74.89744, -100.88366 75.05736, -100.86292 75.64075, -102.50209 75.56380, -102.56552 76.33660, -101.48973 76.30537, -99.98349 76.64634, -98.57699 76.58859, -98.50000 76.72000)), ((-96.01644 80.60233, -95.32345 80.90729, -94.29843 80.97727, -94.73542 81.20646, -92.40984 81.25739, -91.13289 80.72345, -89.45000 80.50932, -87.81000 80.32000, -87.02000 79.66000, -85.81435 79.33690, -87.18756 79.03930, -89.03535 78.28723, -90.80436 78.21533, -92.87669 78.34333, -93.95116 78.75099, -93.93574 79.11373, -93.14524 79.38010, -94.97400 79.37248, -96.07614 79.70502, -96.70972 80.15777, -96.01644 80.60233)), ((-91.58702 81.89429, -90.10000 82.08500, -88.93227 82.11751, -86.97024 82.27961, -85.50000 82.65227, -84.26001 82.60000, -83.18000 82.32000, -82.42000 82.86000, -81.10000 83.02000, -79.30664 83.13056, -76.25000 83.17206, -75.71878 83.06404, -72.83153 83.23324, -70.66577 83.16978, -68.50000 83.10632, -65.82735 83.02801, -63.68000 82.90000, -61.85000 82.62860, -61.89388 82.36165, -64.33400 81.92775, -66.75342 81.72527, -67.65755 81.50141, -65.48031 81.50657, -67.84000 80.90000, -69.46970 80.61683, -71.18000 79.80000, -73.24280 79.63415, -73.88000 79.43016, -76.90773 79.32309, -75.52924 79.19766, -76.22046 79.01907, -75.39345 78.52581, -76.34354 78.18296, -77.88851 77.89991, -78.36269 77.50859, -79.75951 77.20968, -79.61965 76.98336, -77.91089 77.02205, -77.88911 76.77796, -80.56125 76.17812, -83.17439 76.45403, -86.11184 76.29901, -87.60000 76.42000, -89.49068 76.47239, -89.61610 76.95213, -87.76739 77.17833, -88.26000 77.90000, -87.65000 77.97022, -84.97634 77.53873, -86.34000 78.18000, -87.96192 78.37181, -87.15198 78.75867, -85.37868 78.99690, -85.09495 79.34543, -86.50734 79.73624, -86.93179 80.25145, -84.19844 80.20836, -83.40870 80.10000, -81.84823 80.46442, -84.10000 80.58000, -87.59895 80.51627, -89.36663 80.85569, -90.20000 81.26000, -91.36786 81.55310, -91.58702 81.89429)), ((-75.21597 67.44425, -75.86588 67.14886, -76.98687 67.09873, -77.23640 67.58809, -76.81166 68.14856, -75.89521 68.28721, -75.11450 68.01036, -75.10333 67.58202, -75.21597 67.44425)), ((-96.25740 69.49003, -95.64768 69.10769, -96.26952 68.75704, -97.61740 69.06003, -98.43180 68.95070, -99.79740 69.40003, -98.91740 69.71003, -98.21826 70.14354, -97.15740 69.86003, -96.55740 69.68003, -96.25740 69.49003)), ((-64.51912 49.87304, -64.17322 49.95718, -62.85829 49.70641, -61.83558 49.28855, -61.80630 49.10506, -62.29318 49.08717, -63.58926 49.40069, -64.51912 49.87304)), ((-64.01486 47.03601, -63.66450 46.55001, -62.93930 46.41587, -62.01208 46.44314, -62.50391 46.03339, -62.87433 45.96818, -64.14280 46.39265, -64.39261 46.72747, -64.01486 47.03601)))
4328239523.0North AmericaUnited States of AmericaUSA21433226MULTIPOLYGON (((-122.84000 49.00000, -120.00000 49.00000, -117.03121 49.00000, -116.04818 49.00000, -113.00000 49.00000, -110.05000 49.00000, -107.05000 49.00000, -104.04826 48.99986, -100.65000 49.00000, -97.22872 49.00070, -95.15907 49.00000, -95.15609 49.38425, -94.81758 49.38905, -94.64000 48.84000, -94.32914 48.67074, -93.63087 48.60926, -92.61000 48.45000, -91.64000 48.14000, -90.83000 48.27000, -89.60000 48.01000, -89.27292 48.01981, -88.37811 48.30292, -87.43979 47.94000, -86.46199 47.55334, -85.65236 47.22022, -84.87608 46.90008, -84.77924 46.63710, -84.54375 46.53868, -84.60490 46.43960, -84.33670 46.40877, -84.14212 46.51223, -84.09185 46.27542, -83.89077 46.11693, -83.61613 46.11693, -83.46955 45.99469, -83.59285 45.81689, -82.55092 45.34752, -82.33776 44.44000, -82.13764 43.57109, -82.43000 42.98000, -82.90000 42.43000, -83.12000 42.08000, -83.14200 41.97568, -83.02981 41.83280, -82.69009 41.67511, -82.43928 41.67511, -81.27775 42.20903, -80.24745 42.36620, -78.93936 42.86361, -78.92000 42.96500, -79.01000 43.27000, -79.17167 43.46634, -78.72028 43.62509, -77.73789 43.62906, -76.82003 43.62878, -76.50000 44.01846, -76.37500 44.09631, -75.31821 44.81645, -74.86700 45.00048, -73.34783 45.00738, -71.50506 45.00820, -71.40500 45.25500, -71.08482 45.30524, -70.66000 45.46000, -70.30500 45.91500, -69.99997 46.69307, -69.23722 47.44778, -68.90500 47.18500, -68.23444 47.35486, -67.79046 47.06636, -67.79134 45.70281, -67.13741 45.13753, -66.96466 44.80970, -68.03252 44.32520, -69.06000 43.98000, -70.11617 43.68405, -70.64548 43.09024, -70.81489 42.86530, -70.82500 42.33500, -70.49500 41.80500, -70.08000 41.78000, -70.18500 42.14500, -69.88497 41.92283, -69.96503 41.63717, -70.64000 41.47500, -71.12039 41.49445, -71.86000 41.32000, -72.29500 41.27000, -72.87643 41.22065, -73.71000 40.93110, -72.24126 41.11948, -71.94500 40.93000, -73.34500 40.63000, -73.98200 40.62800, -73.95232 40.75075, -74.25671 40.47351, -73.96244 40.42763, -74.17838 39.70926, -74.90604 38.93954, -74.98041 39.19640, -75.20002 39.24845, -75.52805 39.49850, -75.32000 38.96000, -75.07183 38.78203, -75.05673 38.40412, -75.37747 38.01551, -75.94023 37.21689, -76.03127 37.25660, -75.72205 37.93705, -76.23287 38.31921, -76.35000 39.15000, -76.54272 38.71762, -76.32933 38.08326, -76.99000 38.23999, -76.30162 37.91794, -76.25874 36.96640, -75.97180 36.89726, -75.86804 36.55125, -75.72749 35.55074, -76.36318 34.80854, -77.39763 34.51201, -78.05496 33.92547, -78.55435 33.86133, -79.06067 33.49395, -79.20357 33.15839, -80.30132 32.50936, -80.86498 32.03330, -81.33629 31.44049, -81.49042 30.72999, -81.31371 30.03552, -80.98000 29.18000, -80.53558 28.47213, -80.53000 28.04000, -80.05654 26.88000, -80.08801 26.20576, -80.13156 25.81678, -80.38103 25.20616, -80.68000 25.08000, -81.17213 25.20126, -81.33000 25.64000, -81.71000 25.87000, -82.24000 26.73000, -82.70515 27.49504, -82.85526 27.88624, -82.65000 28.55000, -82.93000 29.10000, -83.70959 29.93656, -84.10000 30.09000, -85.10882 29.63615, -85.28784 29.68612, -85.77310 30.15261, -86.40000 30.40000, -87.53036 30.27433, -88.41782 30.38490, -89.18049 30.31598, -89.59383 30.15999, -89.41373 29.89419, -89.43000 29.48864, -89.21767 29.29108, -89.40823 29.15961, -89.77928 29.30714, -90.15463 29.11743, -90.88022 29.14854, -91.62678 29.67700, -92.49906 29.55230, -93.22637 29.78375, -93.84842 29.71363, -94.69000 29.48000, -95.60026 28.73863, -96.59404 28.30748, -97.14000 27.83000, -97.37000 27.38000, -97.38000 26.69000, -97.33000 26.21000, -97.14000 25.87000, -97.53000 25.84000, -98.24000 26.06000, -99.02000 26.37000, -99.30000 26.84000, -99.52000 27.54000, -100.11000 28.11000, -100.45584 28.69612, -100.95760 29.38071, -101.66240 29.77930, -102.48000 29.76000, -103.11000 28.97000, -103.94000 29.27000, -104.45697 29.57196, -104.70575 30.12173, -105.03737 30.64402, -105.63159 31.08383, -106.14290 31.39995, -106.50759 31.75452, -108.24000 31.75485, -108.24194 31.34222, -109.03500 31.34194, -111.02361 31.33472, -113.30498 32.03914, -114.81500 32.52528, -114.72139 32.72083, -115.99135 32.61239, -117.12776 32.53534, -117.29594 33.04622, -117.94400 33.62124, -118.41060 33.74091, -118.51989 34.02778, -119.08100 34.07800, -119.43884 34.34848, -120.36778 34.44711, -120.62286 34.60855, -120.74433 35.15686, -121.71457 36.16153, -122.54747 37.55176, -122.51201 37.78339, -122.95319 38.11371, -123.72720 38.95166, -123.86517 39.76699, -124.39807 40.31320, -124.17886 41.14202, -124.21370 41.99964, -124.53284 42.76599, -124.14214 43.70838, -124.02053 44.61589, -123.89893 45.52341, -124.07963 46.86475, -124.39567 47.72017, -124.68721 48.18443, -124.56610 48.37971, -123.12000 48.04000, -122.58736 47.09600, -122.34000 47.36000, -122.50000 48.18000, -122.84000 49.00000)), ((-155.40214 20.07975, -155.22452 19.99302, -155.06226 19.85910, -154.80741 19.50871, -154.83147 19.45328, -155.22217 19.23972, -155.54211 19.08348, -155.68817 18.91619, -155.93665 19.05939, -155.90806 19.33888, -156.07347 19.70294, -156.02368 19.81422, -155.85008 19.97729, -155.91907 20.17395, -155.86108 20.26721, -155.78505 20.24870, -155.40214 20.07975)), ((-155.99566 20.76404, -156.07926 20.64397, -156.41445 20.57241, -156.58673 20.78300, -156.70167 20.86430, -156.71055 20.92676, -156.61258 21.01249, -156.25711 20.91745, -155.99566 20.76404)), ((-156.75824 21.17684, -156.78933 21.06873, -157.32521 21.09777, -157.25027 21.21958, -156.75824 21.17684)), ((-158.02520 21.71696, -157.94161 21.65272, -157.65283 21.32217, -157.70703 21.26442, -157.77860 21.27729, -158.12667 21.31244, -158.25380 21.53919, -158.29265 21.57912, -158.02520 21.71696)), ((-159.36569 22.21494, -159.34512 21.98200, -159.46372 21.88299, -159.80051 22.06533, -159.74877 22.13820, -159.59620 22.23618, -159.36569 22.21494)), ((-166.46779 60.38417, -165.67443 60.29361, -165.57916 59.90999, -166.19277 59.75444, -166.84834 59.94141, -167.45528 60.21307, -166.46779 60.38417)), ((-153.22873 57.96897, -152.56479 57.90143, -152.14115 57.59106, -153.00631 57.11584, -154.00509 56.73468, -154.51640 56.99275, -154.67099 57.46120, -153.76278 57.81657, -153.22873 57.96897)), ((-140.98599 69.71200, -140.98600 69.71200, -140.99250 66.00003, -140.99778 60.30639, -140.01300 60.27682, -139.03900 60.00000, -138.34089 59.56211, -137.45250 58.90500, -136.47972 59.46389, -135.47583 59.78778, -134.94500 59.27056, -134.27111 58.86111, -133.35556 58.41028, -132.73042 57.69289, -131.70781 56.55212, -130.00778 55.91583, -129.98000 55.28500, -130.53611 54.80278, -130.53611 54.80275, -130.53611 54.80275, -131.08582 55.17891, -131.96721 55.49778, -132.25001 56.37000, -133.53918 57.17889, -134.07806 58.12307, -135.03821 58.18771, -136.62806 58.21221, -137.80001 58.50000, -139.86779 59.53776, -140.82527 59.72752, -142.57444 60.08445, -143.95888 59.99918, -145.92556 60.45861, -147.11437 60.88466, -148.22431 60.67299, -148.01807 59.97833, -148.57082 59.91417, -149.72786 59.70566, -150.60824 59.36821, -151.71639 59.15582, -151.85943 59.74498, -151.40972 60.72580, -150.34694 61.03359, -150.62111 61.28442, -151.89584 60.72720, -152.57833 60.06166, -154.01917 59.35028, -153.28751 58.86473, -154.23249 58.14637, -155.30749 57.72779, -156.30833 57.42277, -156.55610 56.97998, -158.11722 56.46361, -158.43332 55.99415, -159.60333 55.56669, -160.28972 55.64358, -161.22305 55.36473, -162.23777 55.02419, -163.06945 54.68974, -164.78557 54.40417, -164.94223 54.57222, -163.84834 55.03943, -162.87000 55.34804, -161.80417 55.89499, -160.56360 56.00805, -160.07056 56.41806, -158.68444 57.01668, -158.46110 57.21692, -157.72277 57.57000, -157.55027 58.32833, -157.04167 58.91888, -158.19473 58.61580, -158.51722 58.78778, -159.05861 58.42419, -159.71167 58.93139, -159.98129 58.57255, -160.35527 59.07112, -161.35500 58.67084, -161.96889 58.67166, -162.05499 59.26693, -161.87417 59.63362, -162.51806 59.98972, -163.81834 59.79806, -164.66222 60.26748, -165.34639 60.50750, -165.35083 61.07390, -166.12138 61.50002, -165.73445 62.07500, -164.91918 62.63308, -164.56251 63.14638, -163.75333 63.21945, -163.06722 63.05946, -162.26056 63.54194, -161.53445 63.45582, -160.77251 63.76611, -160.95834 64.22280, -161.51807 64.40279, -160.77778 64.78860, -161.39193 64.77724, -162.45305 64.55944, -162.75779 64.33861, -163.54639 64.55916, -164.96083 64.44695, -166.42529 64.68667, -166.84500 65.08890, -168.11056 65.67000, -166.70527 66.08832, -164.47471 66.57666, -163.65251 66.57666, -163.78860 66.07721, -161.67777 66.11612, -162.48971 66.73557, -163.71972 67.11639, -164.43099 67.61634, -165.39029 68.04277, -166.76444 68.35888, -166.20471 68.88303, -164.43081 68.91554, -163.16861 69.37111, -162.93057 69.85806, -161.90890 70.33333, -160.93480 70.44769, -159.03918 70.89164, -158.11972 70.82472, -156.58082 71.35776, -155.06779 71.14778, -154.34417 70.69641, -153.90001 70.88999, -152.21001 70.82999, -152.27000 70.60001, -150.73999 70.43002, -149.72000 70.53001, -147.61336 70.21403, -145.68999 70.12001, -144.92001 69.98999, -143.58945 70.15251, -142.07251 69.85194, -140.98599 69.71200, -140.98599 69.71200)), ((-171.73166 63.78252, -171.11443 63.59219, -170.49111 63.69498, -169.68251 63.43112, -168.68944 63.29751, -168.77194 63.18860, -169.52944 62.97693, -170.29056 63.19444, -170.67139 63.37582, -171.55306 63.31779, -171.79111 63.40585, -171.73166 63.78252)))

The world dataframe has six columns:

  1. pop_est: Estimated population of the country
  2. continent: Name of the continent the country belongs to
  3. name: Human-readable name of the country
  4. iso_a3: Standardized ISO 3166-1 alpha-3 code used as an abbreviated way to represent the country (e.g,. “United States of America” is “USA”, “Tanzania” is “TZA”, etc.)
  5. gdp_md_est: Gross Domestic Product (GDP) in millions of dollars
  6. geometry: A polygon of points/coordinates used to represent the country on a map

The geometry column is the data we are specifically interested in here, as it will allow us to plot each of the countries with Python.

Speaking of which, the following code creates a basic world map with Python:

# initialize an empty figure and add an axis
fig = plt.figure(figsize=(20, 10))
ax = fig.add_subplot()

# plot a basic map of the world
world.plot(
    ax=ax,
    color="lightgray",
    edgecolor="black",
    alpha=0.5
)

# turn off axis ticks
ax.set_xticks([])
ax.set_yticks([])

# set the plot title
plt.title("Basic Map of World with GeoPandas")
plt.show()

Which results in the following image:

Basic world map

I personally like to turn off the plot ticks as it makes the resulting figure a bit less “busy” and easier to read.

Plotting a map of a continent with GeoPandas

Admittedly, it’s been a long time since my elementary school geography class, so I couldn’t remember all the names of the continents (I know, quite embarrassing).

I was also curious which continents had the most countries – I found out by using the value_counts() method on the continent column of the dataframe:

# display the continents, along with the number of countries per continent
world["continent"].value_counts()

Which gives the following output:

continent
Africa                     51
Asia                       47
Europe                     39
North America              18
South America              13
Oceania                     7
Seven seas (open ocean)     1
Antarctica                  1
Name: count, dtype: int64

Turns out that Africa has the most countries, followed closely by Asia.

To plot a single continent with GeoPandas, all you need to do is filter the world dataframe on the continent of Africa:

# initialize a new figure
fig = plt.figure(figsize=(20, 10))
ax = fig.add_subplot()

# grab all African countries
africa = world[world["continent"] == "Africa"]

# plot a basic map of Asia
africa.plot(
    ax=ax,
    cmap="Pastel1",
    edgecolor="black",
    alpha=0.5
)

# turn off axis ticks
ax.set_xticks([])
ax.set_yticks([])

# set the plot title
plt.title("Map of Africa with GeoPandas")
plt.show()

Which results in the following plot of the African continent:

Africa plot

I used a cmap here to give a unique visual distinction to each country on the African continent.

Note: The matplotlib library has a huge number of cmap’s built-into it. You aren’t limited to just one.

Plotting a map of a single country with GeoPandas

Just like we can plot a single continent with GeoPandas, you can also plot a single country.

Here I am filtering out the country of Kenya from the africa dataframe:

# initialize a new figure
fig = plt.figure(figsize=(20, 10))
ax = fig.add_subplot()

# grab the country of Kenya
kenya = africa[africa["name"] == "Kenya"]

# plot a basic map of Kenya
kenya.plot(
    ax=ax,
    cmap="Pastel1",
    edgecolor="black",
    alpha=0.5
)

# turn off axis ticks
ax.set_xticks([])
ax.set_yticks([])

# set the plot title
plt.title("Map of Kenya with GeoPandas")
plt.show()

Which results in the following plot of Kenya:

Plotting multiple countries with GeoPandas

Now, let’s say I wanted to plot multiple countries with GeoPandas and Python.

All I need to do is:

  1. Define a list of country_names that I want to plot
  2. Use the isin() method to filter on the name column (which is the name of the country within a given continent)

The following code does the trick:

# initialize a new figure
fig = plt.figure(figsize=(20, 10))
ax = fig.add_subplot()

# define the names of the countries we want to plot
country_names = [
    "Kenya",
    "Somalia",
    "Uganda",
    "Ethiopia",
    "Sudan",
    "South Sudan",
    "Chad",
    "Cameroon",
]

# grab multiple countries from the continent of Africa
countries = africa[
    africa["name"].isin(country_names)
]

# plot a map of the countries
countries.plot(
    ax=ax,
    cmap="Pastel1",
    edgecolor="black",
    alpha=0.5
)

# turn off axis ticks
ax.set_xticks([])
ax.set_yticks([])

# set the plot title
plt.title("Plotting Multiple Countries with GeoPandas")
plt.show()

Notice how multiple countries have been plotted with GeoPandas:

Plotting multiple countries

Visualizing continents with GeoPandas

One final experiment I played with was visualizing each of the continents with GeoPandas by creating a unique color overlay of the countries belonging to each of the respective continents (i.e., quickly visualizing the countries that make up North America, South America, Europe, etc.).

To start, I dropped “Antarctica” and the “Seven seas” from the world dataframe, which resulted in a prettier world map:

# initialize a final empty figure
fig = plt.figure(figsize=(20, 10))
ax = fig.add_subplot()

# drop "Antarctica" and "Seven seas" from the dataframe (which will make our
# world map visualization a bit prettier)
drop_idxs = world["continent"].isin([
    "Antarctica",
    "Seven seas (open ocean)"
])
world = world.drop(world[drop_idxs].index)

I then plotted a boundary map of the world:

# start by plotting a map of the world
world.boundary.plot(
    ax=ax,
    color="black",
    linewidth=0.5
)

A boundary map (as opposed to a normal map) is effectively just an outline of the countries/continents of the world:

Boundary map

Finally, I was ready to create the color overlay for each of the continents.

There were a number of ways to accomplish this task, but the easiest way I found was to:

  1. Use Seaborn’s color_palette function to generate a unique color for each continent
  2. Loop over the continents (and respective visualization colors)
  3. Filter on the current continent
  4. Use the .plot method of the continent dataframe, along with the axis (ax) from the boundary plot, to draw the continent overlay

Here is the code I used to create the continent visualization:

# grab the unique set of continents, generate a unique color for each one,
# and initialize the list of patches
continents = world["continent"].unique()
colors = sns.color_palette("Set3", len(continents))
patches = []

# loop over the continent names and corresponding colors
for (continent_name, color) in list(zip(continents, colors)):
    # grab all countries that belong to the continent, then plot each of the
    # continents, giving each a unique color
    continent = world[world["continent"] == continent_name]
    continent.plot(ax=ax, color=color, alpha=0.5)

    # generate a patch for the current continent
    patch = mpatches.Patch(label=continent_name, color=color)
    patches.append(patch)

# add the patches to the map
ax.legend(handles=patches, loc="lower left")

# turn off axis ticks
ax.set_xticks([])
ax.set_yticks([])

# set the plot title
plt.title("Continents of the World with GeoPandas")
plt.show()

And here is the resulting world map:

Boundary map with overlay

At this point I feel comfortable plotting geographical regions, specifically countries and continents, with GeoPandas.

I’ll be building on this code in future experiments where I:

  • Plot a map of the United States with GeoPandas
  • Visualize Tornado Alley and Dixie Alley with GeoPandas
  • Analyze major tornadoes in the United States and plot them

I’ll share those results once I get around to coding them.

Takeaways

  • EM-DAT Exploration: The motivation to explore geographical plotting originated from my interest in the EM-DAT database which holds records of major natural disasters since 1900.
  • GeoPandas Basics: To plot a map of the world, I found GeoPandas to be immensely helpful. It offers an in-built dataset naturalearth_lowres that provides a low-resolution map of the world, ready for visualization.
  • Plotting a World Map: A few lines of Python code with GeoPandas can produce a basic world map. The world dataframe in GeoPandas contains columns detailing each country’s population, GDP, ISO codes, and crucially, their geographical boundaries.
  • Zooming into Continents and Countries: I demonstrated how you can visualize a specific continent (like Africa) or even a single country (like Kenya). GeoPandas makes it easy to filter and plot regions of interest.
  • Multiple Countries Visualization: By defining a list of countries of interest, we can visualize multiple countries in one go.
  • Boundary Maps and Continent Overlays: Beyond just plotting standard maps, we also delved into creating boundary maps, which are essentially the outlines of countries. We even overlaid each continent with unique colors for a more striking visual.
  • Future Work: Building on this foundational knowledge, I plan to delve deeper into visualizing specific regions like Tornado Alley and Dixie Alley. I’ll also analyze and plot major tornado events in the U.S.

Citation information

Adrian Rosebrock. “How to Plot a World Map Using Python and GeoPandas”, NaturalDisasters.ai, 2023, https://naturaldisasters.ai/posts/python-geopandas-world-map-tutorial/.

@incollection{ARosebrock_PlotWorldMapGeoPandas,
    author = {Adrian Rosebrock},
    title = {How to Plot a World Map Using Python and GeoPandas},
    booktitle = {NaturalDisasters.ai},
    year = {2023},
    url = {https://naturaldisasters.ai/posts/python-geopandas-world-map-tutorial/},
}

AI generated content disclaimer: I’ve used a sprinkling of AI magic in this blog post, namely in the “Takeaways” section, where I used AI to create a concise summary of this article. Don’t fret, my human eyeballs have read and edited every word of the AI generated content, so rest assured, what you’re reading is as accurate as I possibly can make it. If there are any discrepancies or inaccuracies in the post, it’s my fault, not that of our machine assistants.

Header photo by Andrew Stutesman on Unsplash