From 5265dcb5c490bd158916c0a3947519523ce822c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Thu, 27 Nov 2025 09:37:21 +0100 Subject: [PATCH 01/13] Use Natural Earth data --- examples/gallery/maps/choropleth_map.py | 43 +++++++++++-------------- 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/examples/gallery/maps/choropleth_map.py b/examples/gallery/maps/choropleth_map.py index f1cce8c3014..f73bd3d5d13 100644 --- a/examples/gallery/maps/choropleth_map.py +++ b/examples/gallery/maps/choropleth_map.py @@ -14,45 +14,40 @@ """ # %% -import geodatasets import geopandas as gpd import pygmt -# Read the example dataset provided by geodatasets. -gdf = gpd.read_file(geodatasets.get_path("geoda airbnb")) -print(gdf.head()) +provider = "https://naciscdn.org/naturalearth/" +world = gpd.read_file(f"{provider}50m/cultural/ne_50m_admin_0_countries.zip") +world["POP_EST"] *= 1e-6 +world = world[world["CONTINENT"] == "Africa"] +region = [-13, 27, 36, 63] # Europe +region = [-89, -33, -56.5, 10] # South America +region = [-19.5, 53, -37.5, 38] # Africa -# %% fig = pygmt.Figure() +fig.basemap(region=region, projection="M15c", frame="+n") -fig.basemap( - region=gdf.total_bounds[[0, 2, 1, 3]], - projection="M6c", - frame="+tPopulation of Chicago", -) +# The dataset contains different attributes, here we focus on the population within +# the different countries (column "POP_EST"). -# The dataset contains different attributes, here we select the "population" column to -# plot. - -# First, we define the colormap to fill the polygons based on the "population" column. -pygmt.makecpt( - cmap="acton", - series=[gdf["population"].min(), gdf["population"].max(), 10], - continuous=True, - reverse=True, -) +# First, we define the colormap to fill the polygons based on the "POP_EST" column. +pygmt.makecpt(cmap="acton", series=(0, 100), reverse=True) # Next, we plot the polygons and fill them using the defined colormap. The target column # is defined by the aspatial parameter. fig.plot( - data=gdf, - pen="0.3p,gray10", + data=world[["POP_EST", "geometry"]], + pen="1p,gray50", fill="+z", cmap=True, - aspatial="Z=population", + aspatial="Z=POP_EST", ) # Add colorbar legend. -fig.colorbar(frame="x+lPopulation", position="jML+o-0.5c+w3.5c/0.2c") +fig.colorbar( + frame="x10f5+lPopulation (millions)", + position="jML+o3c/-3.5c+w7.5c+ef0.3c+ml", +) fig.show() From 8cc47de9c59bad0fc0342d2258a4c86ffd50fc9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Thu, 27 Nov 2025 10:55:10 +0100 Subject: [PATCH 02/13] Focus on Africa --- examples/gallery/maps/choropleth_map.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/examples/gallery/maps/choropleth_map.py b/examples/gallery/maps/choropleth_map.py index f73bd3d5d13..754ecfc6300 100644 --- a/examples/gallery/maps/choropleth_map.py +++ b/examples/gallery/maps/choropleth_map.py @@ -20,13 +20,9 @@ provider = "https://naciscdn.org/naturalearth/" world = gpd.read_file(f"{provider}50m/cultural/ne_50m_admin_0_countries.zip") world["POP_EST"] *= 1e-6 -world = world[world["CONTINENT"] == "Africa"] -region = [-13, 27, 36, 63] # Europe -region = [-89, -33, -56.5, 10] # South America -region = [-19.5, 53, -37.5, 38] # Africa fig = pygmt.Figure() -fig.basemap(region=region, projection="M15c", frame="+n") +fig.basemap(region=[-19.5, 53, -37.5, 38], projection="M15c", frame="+n") # The dataset contains different attributes, here we focus on the population within # the different countries (column "POP_EST"). @@ -37,7 +33,7 @@ # Next, we plot the polygons and fill them using the defined colormap. The target column # is defined by the aspatial parameter. fig.plot( - data=world[["POP_EST", "geometry"]], + data=world[world["CONTINENT"] == "Africa"], pen="1p,gray50", fill="+z", cmap=True, From 0f09744d0c8935859a3ce6f0bba84dd7e6c94cc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Thu, 27 Nov 2025 11:25:01 +0100 Subject: [PATCH 03/13] Adjust URL --- examples/gallery/maps/choropleth_map.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/gallery/maps/choropleth_map.py b/examples/gallery/maps/choropleth_map.py index 754ecfc6300..2b10406f24a 100644 --- a/examples/gallery/maps/choropleth_map.py +++ b/examples/gallery/maps/choropleth_map.py @@ -17,8 +17,8 @@ import geopandas as gpd import pygmt -provider = "https://naciscdn.org/naturalearth/" -world = gpd.read_file(f"{provider}50m/cultural/ne_50m_admin_0_countries.zip") +provider = "https://naciscdn.org/naturalearth" +world = gpd.read_file(f"{provider}/50m/cultural/ne_50m_admin_0_countries.zip") world["POP_EST"] *= 1e-6 fig = pygmt.Figure() From d9d047887344facac3df3c546253680c96a632a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Thu, 27 Nov 2025 11:26:07 +0100 Subject: [PATCH 04/13] Move comment --- examples/gallery/maps/choropleth_map.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/gallery/maps/choropleth_map.py b/examples/gallery/maps/choropleth_map.py index 2b10406f24a..fe83f726860 100644 --- a/examples/gallery/maps/choropleth_map.py +++ b/examples/gallery/maps/choropleth_map.py @@ -19,14 +19,14 @@ provider = "https://naciscdn.org/naturalearth" world = gpd.read_file(f"{provider}/50m/cultural/ne_50m_admin_0_countries.zip") + +# The dataset contains different attributes, here we focus on the population within +# the different countries (column "POP_EST"). world["POP_EST"] *= 1e-6 fig = pygmt.Figure() fig.basemap(region=[-19.5, 53, -37.5, 38], projection="M15c", frame="+n") -# The dataset contains different attributes, here we focus on the population within -# the different countries (column "POP_EST"). - # First, we define the colormap to fill the polygons based on the "POP_EST" column. pygmt.makecpt(cmap="acton", series=(0, 100), reverse=True) From 3c5a0bacaed78e9aa1699138f76d49fb6ab3aeb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Thu, 27 Nov 2025 11:29:01 +0100 Subject: [PATCH 05/13] Fix geopandas warning --- examples/gallery/maps/choropleth_map.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/gallery/maps/choropleth_map.py b/examples/gallery/maps/choropleth_map.py index fe83f726860..227812b6239 100644 --- a/examples/gallery/maps/choropleth_map.py +++ b/examples/gallery/maps/choropleth_map.py @@ -33,7 +33,7 @@ # Next, we plot the polygons and fill them using the defined colormap. The target column # is defined by the aspatial parameter. fig.plot( - data=world[world["CONTINENT"] == "Africa"], + data=world[world["CONTINENT"] == "Africa"].copy(), pen="1p,gray50", fill="+z", cmap=True, From e2b00514dc2ee5e1a2a74436dd22fa659214a4ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Thu, 27 Nov 2025 11:48:31 +0100 Subject: [PATCH 06/13] Improve comment and define seperate variable for subset --- examples/gallery/maps/choropleth_map.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/gallery/maps/choropleth_map.py b/examples/gallery/maps/choropleth_map.py index 227812b6239..2b4c6f31c8e 100644 --- a/examples/gallery/maps/choropleth_map.py +++ b/examples/gallery/maps/choropleth_map.py @@ -21,8 +21,9 @@ world = gpd.read_file(f"{provider}/50m/cultural/ne_50m_admin_0_countries.zip") # The dataset contains different attributes, here we focus on the population within -# the different countries (column "POP_EST"). +# the different countries (column "POP_EST") for the continent "Africa". world["POP_EST"] *= 1e-6 +world_africa = world[world["CONTINENT"] == "Africa"].copy() fig = pygmt.Figure() fig.basemap(region=[-19.5, 53, -37.5, 38], projection="M15c", frame="+n") @@ -33,7 +34,7 @@ # Next, we plot the polygons and fill them using the defined colormap. The target column # is defined by the aspatial parameter. fig.plot( - data=world[world["CONTINENT"] == "Africa"].copy(), + data=word_africa, pen="1p,gray50", fill="+z", cmap=True, From 7123d65f63895a65920f5928ee3bdd834826a0e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Thu, 27 Nov 2025 11:53:21 +0100 Subject: [PATCH 07/13] Fix typo in code --- examples/gallery/maps/choropleth_map.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/gallery/maps/choropleth_map.py b/examples/gallery/maps/choropleth_map.py index 2b4c6f31c8e..513fbf7453c 100644 --- a/examples/gallery/maps/choropleth_map.py +++ b/examples/gallery/maps/choropleth_map.py @@ -34,7 +34,7 @@ # Next, we plot the polygons and fill them using the defined colormap. The target column # is defined by the aspatial parameter. fig.plot( - data=word_africa, + data=world_africa, pen="1p,gray50", fill="+z", cmap=True, From 1ce6224c33c5b3277efd21d1835255b690b547db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Thu, 27 Nov 2025 11:54:30 +0100 Subject: [PATCH 08/13] Use full line length --- examples/gallery/maps/choropleth_map.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/examples/gallery/maps/choropleth_map.py b/examples/gallery/maps/choropleth_map.py index 513fbf7453c..168af167336 100644 --- a/examples/gallery/maps/choropleth_map.py +++ b/examples/gallery/maps/choropleth_map.py @@ -33,18 +33,11 @@ # Next, we plot the polygons and fill them using the defined colormap. The target column # is defined by the aspatial parameter. -fig.plot( - data=world_africa, - pen="1p,gray50", - fill="+z", - cmap=True, - aspatial="Z=POP_EST", -) +fig.plot(data=world_africa, pen="1p,gray50", fill="+z", cmap=True, aspatial="Z=POP_EST") # Add colorbar legend. fig.colorbar( - frame="x10f5+lPopulation (millions)", - position="jML+o3c/-3.5c+w7.5c+ef0.3c+ml", + frame="x10f5+lPopulation (millions)", position="jML+o3c/-3.5c+w7.5c+ef0.3c+ml" ) fig.show() From f4bb509fba7a0374d4affe1e744daf4fa09cebe1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Thu, 27 Nov 2025 13:21:23 +0100 Subject: [PATCH 09/13] Reduce map width --- examples/gallery/maps/choropleth_map.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/gallery/maps/choropleth_map.py b/examples/gallery/maps/choropleth_map.py index 168af167336..d5f52ebab44 100644 --- a/examples/gallery/maps/choropleth_map.py +++ b/examples/gallery/maps/choropleth_map.py @@ -26,7 +26,7 @@ world_africa = world[world["CONTINENT"] == "Africa"].copy() fig = pygmt.Figure() -fig.basemap(region=[-19.5, 53, -37.5, 38], projection="M15c", frame="+n") +fig.basemap(region=[-19.5, 53, -37.5, 38], projection="M10c", frame="+n") # First, we define the colormap to fill the polygons based on the "POP_EST" column. pygmt.makecpt(cmap="acton", series=(0, 100), reverse=True) From 5a7cc1350e3dace9e92a2bd9ad1b621ab6c3bea7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Thu, 27 Nov 2025 17:39:19 +0100 Subject: [PATCH 10/13] Adjust map size --- examples/gallery/maps/choropleth_map.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/gallery/maps/choropleth_map.py b/examples/gallery/maps/choropleth_map.py index d5f52ebab44..168af167336 100644 --- a/examples/gallery/maps/choropleth_map.py +++ b/examples/gallery/maps/choropleth_map.py @@ -26,7 +26,7 @@ world_africa = world[world["CONTINENT"] == "Africa"].copy() fig = pygmt.Figure() -fig.basemap(region=[-19.5, 53, -37.5, 38], projection="M10c", frame="+n") +fig.basemap(region=[-19.5, 53, -37.5, 38], projection="M15c", frame="+n") # First, we define the colormap to fill the polygons based on the "POP_EST" column. pygmt.makecpt(cmap="acton", series=(0, 100), reverse=True) From b967bdc3bf36ea5be80d65e02e6beac68b8f9104 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Thu, 27 Nov 2025 18:07:26 +0100 Subject: [PATCH 11/13] Adjust map size and colorbar length and size --- examples/gallery/maps/choropleth_map.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/gallery/maps/choropleth_map.py b/examples/gallery/maps/choropleth_map.py index 168af167336..958fe3e525b 100644 --- a/examples/gallery/maps/choropleth_map.py +++ b/examples/gallery/maps/choropleth_map.py @@ -26,18 +26,18 @@ world_africa = world[world["CONTINENT"] == "Africa"].copy() fig = pygmt.Figure() -fig.basemap(region=[-19.5, 53, -37.5, 38], projection="M15c", frame="+n") +fig.basemap(region=[-19.5, 53, -37.5, 38], projection="M10c", frame="+n") # First, we define the colormap to fill the polygons based on the "POP_EST" column. pygmt.makecpt(cmap="acton", series=(0, 100), reverse=True) # Next, we plot the polygons and fill them using the defined colormap. The target column # is defined by the aspatial parameter. -fig.plot(data=world_africa, pen="1p,gray50", fill="+z", cmap=True, aspatial="Z=POP_EST") +fig.plot(data=world_africa, pen="0.8p,gray50", fill="+z", cmap=True, aspatial="Z=POP_EST") # Add colorbar legend. fig.colorbar( - frame="x10f5+lPopulation (millions)", position="jML+o3c/-3.5c+w7.5c+ef0.3c+ml" + frame="x10f5+lPopulation (millions)", position="jML+o2c/-2.5c+w5c+ef0.2c+ml" ) fig.show() From 5c784a84d9154e1bd9681a5a86c973b85d83c437 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Thu, 27 Nov 2025 18:17:15 +0100 Subject: [PATCH 12/13] Adjust code to match line length --- examples/gallery/maps/choropleth_map.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/examples/gallery/maps/choropleth_map.py b/examples/gallery/maps/choropleth_map.py index 958fe3e525b..8bbf60a5caf 100644 --- a/examples/gallery/maps/choropleth_map.py +++ b/examples/gallery/maps/choropleth_map.py @@ -23,7 +23,7 @@ # The dataset contains different attributes, here we focus on the population within # the different countries (column "POP_EST") for the continent "Africa". world["POP_EST"] *= 1e-6 -world_africa = world[world["CONTINENT"] == "Africa"].copy() +africa = world[world["CONTINENT"] == "Africa"].copy() fig = pygmt.Figure() fig.basemap(region=[-19.5, 53, -37.5, 38], projection="M10c", frame="+n") @@ -33,11 +33,9 @@ # Next, we plot the polygons and fill them using the defined colormap. The target column # is defined by the aspatial parameter. -fig.plot(data=world_africa, pen="0.8p,gray50", fill="+z", cmap=True, aspatial="Z=POP_EST") +fig.plot(data=africa, pen="0.8p,gray50", fill="+z", cmap=True, aspatial="Z=POP_EST") # Add colorbar legend. -fig.colorbar( - frame="x10f5+lPopulation (millions)", position="jML+o2c/-2.5c+w5c+ef0.2c+ml" -) +fig.colorbar(frame="x+lPopulation (millions)", position="jML+o2c/-2.5c+w5c+ef0.2c+ml") fig.show() From f21bf4b31a6efe614b5653f7afb5c041c37790b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= <94163266+yvonnefroehlich@users.noreply.github.com> Date: Fri, 28 Nov 2025 08:29:23 +0100 Subject: [PATCH 13/13] Change to 110 m Co-authored-by: Dongdong Tian --- examples/gallery/maps/choropleth_map.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/gallery/maps/choropleth_map.py b/examples/gallery/maps/choropleth_map.py index 8bbf60a5caf..d03c6a988be 100644 --- a/examples/gallery/maps/choropleth_map.py +++ b/examples/gallery/maps/choropleth_map.py @@ -18,7 +18,7 @@ import pygmt provider = "https://naciscdn.org/naturalearth" -world = gpd.read_file(f"{provider}/50m/cultural/ne_50m_admin_0_countries.zip") +world = gpd.read_file(f"{provider}/110m/cultural/ne_110m_admin_0_countries.zip") # The dataset contains different attributes, here we focus on the population within # the different countries (column "POP_EST") for the continent "Africa".