Skip to content
Open
Show file tree
Hide file tree
Changes from 65 commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
f781946
Add draft of JN for geopandas - geodataframes with lines and polygons
yvonnefroehlich Dec 24, 2024
93afa24
Include output figure
yvonnefroehlich Jan 4, 2025
587da3a
Reduce resolution of output image in JN
yvonnefroehlich Jan 4, 2025
fc103e9
Follow coding style
yvonnefroehlich Jan 5, 2025
57511d0
Adjust filename
yvonnefroehlich Jan 5, 2025
01812e8
Remove comments | Improve code structure
yvonnefroehlich Oct 16, 2025
e288455
Move to normal python script (temporaly)
yvonnefroehlich Nov 5, 2025
fb445fd
Rename files and save output figure
yvonnefroehlich Nov 12, 2025
6c58129
Add codes for choropleth map based on dcw parameter
yvonnefroehlich Nov 13, 2025
0e321e0
Merge remote-tracking branch 'origin/main' into fig/geopandas
yvonnefroehlich Nov 16, 2025
c885c52
Add code for example covering points, lines, and polygons
yvonnefroehlich Nov 19, 2025
ab2ca00
Remove code for chorophleth via dcw
yvonnefroehlich Nov 19, 2025
c6a39c1
Remove unneeded files
yvonnefroehlich Nov 19, 2025
65c458b
Adjust codes for example with natural earth data | temporly focus on …
yvonnefroehlich Nov 20, 2025
012e5fb
Test different regions
yvonnefroehlich Nov 21, 2025
8cb2e58
Remove content for Cicago example
yvonnefroehlich Nov 21, 2025
af55d14
Change scaling to e-6
yvonnefroehlich Nov 21, 2025
7042382
Use 1e-6
yvonnefroehlich Nov 21, 2025
40f4390
Adjust figure number
yvonnefroehlich Nov 21, 2025
dd18459
Adjust color and remove unneeded pen color
yvonnefroehlich Nov 21, 2025
80a0648
Focus on Africa
yvonnefroehlich Nov 21, 2025
8996b68
Use different symobl fill and size for world and smaller cities
yvonnefroehlich Nov 26, 2025
f979b8b
Adjust fill, outline and offset of text labels
yvonnefroehlich Nov 26, 2025
fb6e595
Adjust maximum for CPT to 100
yvonnefroehlich Nov 26, 2025
a3218a5
Follow coding style
yvonnefroehlich Nov 27, 2025
8938542
No need to explecitly select the "geometry" column
yvonnefroehlich Nov 27, 2025
ad7a1bd
Adjust provider | Fix geopandas warning | Use full line length
yvonnefroehlich Nov 27, 2025
61c98f1
Add backslash
yvonnefroehlich Nov 27, 2025
cba722d
Merge remote-tracking branch 'origin/main' into fig/geopandas
yvonnefroehlich Nov 27, 2025
b19ddf0
Adust colormap maximum and colorbar
yvonnefroehlich Nov 27, 2025
561bb43
Adjust color for rivers
yvonnefroehlich Nov 27, 2025
f1eb469
Adjust text labels
yvonnefroehlich Nov 27, 2025
bedf467
Add just colorbar frame
yvonnefroehlich Nov 27, 2025
447c51b
Plot colorbar verticall inside the map
yvonnefroehlich Nov 27, 2025
6e84e65
Update output image
yvonnefroehlich Nov 27, 2025
686b661
Adjust region
yvonnefroehlich Nov 27, 2025
74bcc3a
TEMPORALY add code for focus on Africa
yvonnefroehlich Nov 27, 2025
2d60504
Remove geometry column
yvonnefroehlich Nov 27, 2025
324af82
Use rivers for 110 m
yvonnefroehlich Nov 27, 2025
6eca7da
Update output image
yvonnefroehlich Nov 27, 2025
d0f4920
Merge remote-tracking branch 'origin/main' into fig/geopandas
yvonnefroehlich Nov 27, 2025
645ff9c
Adjust and shorten variable names
yvonnefroehlich Nov 27, 2025
b119528
Use gpd.sjoin instead of pd.concat
yvonnefroehlich Nov 28, 2025
3ed5e1f
Remove unneeded pandas import
yvonnefroehlich Nov 28, 2025
2b4c6b9
Adjust building the city subsets
yvonnefroehlich Nov 28, 2025
7bd7935
Use 110 m also for population
yvonnefroehlich Nov 28, 2025
c45cc6f
Remove geometry column
yvonnefroehlich Nov 28, 2025
ae24b2e
Remove code for old version
yvonnefroehlich Nov 28, 2025
dc38ff0
Update output images
yvonnefroehlich Nov 28, 2025
9effeee
Remove geometry column
yvonnefroehlich Nov 28, 2025
45b56ed
Merge remote-tracking branch 'origin/main' into fig/geopandas
yvonnefroehlich Nov 29, 2025
1653b66
Add codes for Chicago map
yvonnefroehlich Nov 30, 2025
4ba60d6
Improve visualization
yvonnefroehlich Nov 30, 2025
269765d
Add lake
yvonnefroehlich Nov 30, 2025
6c2c772
Merge remote-tracking branch 'origin/main' into fig/geopandas
yvonnefroehlich Nov 30, 2025
07d84c9
Polish code
yvonnefroehlich Nov 30, 2025
1e537a4
Update output figure
yvonnefroehlich Nov 30, 2025
86fbfa7
Use Box class
yvonnefroehlich Nov 30, 2025
1adf58f
Merge remote-tracking branch 'origin/main' into fig/geopandas
yvonnefroehlich Dec 1, 2025
8d07359
Add draft for usa area chorophlet map with rivers and cities
yvonnefroehlich Dec 1, 2025
1de1fd6
Adjust color of rivers
yvonnefroehlich Dec 1, 2025
6ad8285
Start colormap at zero
yvonnefroehlich Dec 1, 2025
97789ee
Update output image
yvonnefroehlich Dec 1, 2025
13c3d3c
Do not subset cities | Use rivers from 110 m dataset | Remove geometr…
yvonnefroehlich Dec 2, 2025
08bbc86
Improve data request
yvonnefroehlich Dec 2, 2025
a811284
Select rivers and cities located in USA
yvonnefroehlich Dec 2, 2025
8a5daaa
Exclude Alaska | Increase thickness of colorbar | Upate output figure
yvonnefroehlich Dec 2, 2025
8eb566a
Remove codes and images of old examples
yvonnefroehlich Dec 2, 2025
477e7b4
Plot Alaska and Hawaii at the lower-left corner
yvonnefroehlich Dec 2, 2025
0826ef4
Do not exclude Alaska
yvonnefroehlich Dec 2, 2025
785502d
Remove codes from old examples
yvonnefroehlich Dec 2, 2025
a7f3262
Adjust position of colorbar
yvonnefroehlich Dec 2, 2025
7d01582
Combine into loop
yvonnefroehlich Dec 2, 2025
42693a2
Adjust colorbar | Improve comment
yvonnefroehlich Dec 2, 2025
55dc3fb
Add missing word
yvonnefroehlich Dec 2, 2025
ae06ce9
Improve preparing the subsets
yvonnefroehlich Dec 2, 2025
e1121f2
Use color map hawaii
yvonnefroehlich Dec 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions Fig6_PyGMT_geopandas.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "760146f6-d4c9-4e69-b539-f42e057c7945",
"metadata": {},
"outputs": [],
"source": [
"# Copy finale version of script from normal Python file"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.3"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
144 changes: 144 additions & 0 deletions Fig6_PyGMT_geopandas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
import geopandas as gpd
import pygmt

provider = "https://naciscdn.org/naturalearth"
states = gpd.read_file(f"{provider}/110m/cultural/ne_110m_admin_1_states_provinces.zip")
states["area_sqkm"] = states.geometry.to_crs(epsg=6933).area / 10 ** 9
states = states[states["name"] != "Alaska"]
rivers = gpd.read_file(f"{provider}/110m/physical/ne_110m_rivers_lake_centerlines.zip")
rivers = rivers.cx[-126:-66, 24.9:49.1]
cities = gpd.read_file(f"{provider}/110m/cultural/ne_110m_populated_places_simple.zip")
cities = cities.cx[-126:-66, 25.7:42]

fig = pygmt.Figure()
fig.basemap(projection="L-96/35/33/41/12c", region=[-126, -66, 25, 49], frame="+n")

pygmt.makecpt(cmap="bilbao", series=[0, states["area_sqkm"].max()])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use a different CPT or a different range, to avoid polygons that are too light or too dark?

Copy link
Member Author

@yvonnefroehlich yvonnefroehlich Dec 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually not so easy, as Alaska is so much larger and Hawaii so much smaller than the other states.

hawaii nuuk imola bamako
hawaii nuuk imola bamako
acton batlow navia bilbao (currently)
acton batlow navia image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe "hawaii" is better?

Copy link
Member Author

@yvonnefroehlich yvonnefroehlich Dec 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, from the CPTs I tested I think "hawaii" is the best (even I am not really a fan of the colors in this colormap itself).
I have chaged the colormap in commit e1121f2. Also played around with a logarithmic scaling, but did not improve the image.

fig.plot(data=states, cmap=True, pen="0.2p,gray50", fill="+z", aspatial="Z=area_sqkm")
fig.colorbar(frame="xaf+lArea (1000 km@+2@+)", position="jBL+h+o1.4c/0.6c+w3.5c+ml")

fig.plot(data=rivers, pen="0.5p,dodgerblue4")

fig.plot(data=cities, style="s0.17c", fill="darkorange", pen="0.5p")
fig.text(
x=cities.geometry.x,
y=cities.geometry.y,
text=cities["name"],
offset="0.35c/0.2c",
justify="BC",
font="4.5p,Helvetica-Bold",
fill="white@30",
pen="0.2p,darkorange",
clearance="0.05c+tO",
)

fig.show()
fig.savefig(fname="Fig6_PyGMT_geopandas_usa.png")


# %%
import geodatasets
import geopandas as gpd
import pygmt
from pygmt.params import Box

chicago = gpd.read_file(geodatasets.get_path("geoda airbnb"))

provider = "https://naciscdn.org/naturalearth"
files = {
"railroads": "ne_10m_railroads.zip",
"airports": "ne_10m_airports.zip",
"cities": "ne_10m_populated_places_simple.zip",
"ports": "ne_10m_ports.zip",
}

# define bounding box
bbox = (-87.94, -87.52, 41.64, 42.02)

data = {}
for key, fname in files.items():
gdf = gpd.read_file(f"{provider}/10m/cultural/{fname}")
data[key] = gdf.cx[bbox[0]:bbox[1], bbox[2]:bbox[3]]

railroads = data["railroads"]
airports = data["airports"]
cities = data["cities"]
ports = data["ports"]


fig = pygmt.Figure()
fig.basemap(region=chicago.total_bounds[[0, 2, 1, 3]], projection="M10c", frame="+n")
fig.coast(shorelines=True, lakes="lightblue", land="gray95")

pygmt.makecpt(cmap="bilbao", series=[0, chicago["population"].max()])

fig.plot(data=chicago, pen="0.5p,gray30", fill="+z", cmap=True, aspatial="Z=population")

fig.plot(data=railroads["geometry"], pen="2p,black")
fig.plot(data=railroads["geometry"], pen="1p,white,2_2")

fig.plot(data=cities["geometry"], style="s0.32c", fill="red", pen="1p", label="city")
fig.plot(data=ports["geometry"], style="i0.35c", fill="steelblue", pen="1p", label="harbor")
fig.plot(data=airports["geometry"], style="t0.35c", fill="darkorange", pen="1p", label="airport")
fig.text(
x=airports.geometry.x,
y=airports.geometry.y,
text=airports["name"],
offset="-0.25c",
justify="TL",
font="8p,Helvetica-Bold",
fill="white@30",
pen="0.8p,darkorange",
clearance="0.08c+tO",
)

fig.colorbar(
frame="xaf+lPopulation in Chicago",
position="jML+o0.95c/-1.5c+w7c+ml",
box=Box(fill="gray95", clearance="0.5c"),
)
fig.legend(position="jTR+o0.2c+l1.7", box=Box(fill="white@30", pen="0.5p,gray50"))

fig.show()
fig.savefig(fname="Fig6_PyGMT_geopandas_chicago.png")


# %%
import geopandas as gpd
import pygmt

provider = "https://naciscdn.org/naturalearth"
world = gpd.read_file(f"{provider}/110m/cultural/ne_110m_admin_0_countries.zip")
world["POP_EST"] *= 1e-6
africa = world[world["CONTINENT"] == "Africa"].copy()
rivers = gpd.read_file(f"{provider}/110m/physical/ne_110m_rivers_lake_centerlines.zip")
cities = gpd.read_file(f"{provider}/110m/cultural/ne_110m_populated_places_simple.zip")
cities_africa = gpd.sjoin(cities, africa, how="inner")
cities_large = cities_africa[cities_africa["worldcity"] == 1].copy()
cities_small = cities_africa[cities_africa["worldcity"] != 1].copy()

fig = pygmt.Figure()
fig.basemap(region=[-19.5, 52, -37, 38], projection="M15c", frame="+n")

pygmt.makecpt(cmap="bilbao", series=(0, 200))
fig.plot(data=africa, pen="0.8p,gray50", fill="+z", cmap=True, aspatial="Z=POP_EST")
fig.colorbar(frame="x20f10+lPopulation (millions)", position="jML+o3c/-3.5c+w7.5c+ml")

fig.plot(data=rivers, pen="1.5p,dodgerblue4")

fig.plot(data=cities_small, style="s0.2c", fill="lightgray", pen="1p")
fig.plot(data=cities_large, style="s0.3c", fill="darkorange", pen="1p")
fig.text(
x=cities_large.geometry.x,
y=cities_large.geometry.y,
text=cities_large["name"],
offset="0.2c/0.35c",
justify="BL",
font="10p,Helvetica-Bold",
fill="white@30",
pen="0.8p,darkorange",
clearance="0.1c+tO",
)

fig.show()
fig.savefig(fname="Fig6_PyGMT_geopandas_africa.png")
Binary file added Fig6_PyGMT_geopandas_africa.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Fig6_PyGMT_geopandas_chicago.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Fig6_PyGMT_geopandas_usa.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.