|
14 | 14 | """ |
15 | 15 |
|
16 | 16 | # %% |
17 | | -import geodatasets |
18 | 17 | import geopandas as gpd |
19 | 18 | import pygmt |
20 | 19 |
|
21 | | -# Read the example dataset provided by geodatasets. |
22 | | -gdf = gpd.read_file(geodatasets.get_path("geoda airbnb")) |
23 | | -print(gdf.head()) |
| 20 | +provider = "https://naciscdn.org/naturalearth" |
| 21 | +world = gpd.read_file(f"{provider}/110m/cultural/ne_110m_admin_0_countries.zip") |
24 | 22 |
|
25 | | -# %% |
26 | | -fig = pygmt.Figure() |
| 23 | +# The dataset contains different attributes, here we focus on the population within |
| 24 | +# the different countries (column "POP_EST") for the continent "Africa". |
| 25 | +world["POP_EST"] *= 1e-6 |
| 26 | +africa = world[world["CONTINENT"] == "Africa"].copy() |
27 | 27 |
|
28 | | -fig.basemap( |
29 | | - region=gdf.total_bounds[[0, 2, 1, 3]], |
30 | | - projection="M6c", |
31 | | - frame="+tPopulation of Chicago", |
32 | | -) |
33 | | - |
34 | | -# The dataset contains different attributes, here we select the "population" column to |
35 | | -# plot. |
| 28 | +fig = pygmt.Figure() |
| 29 | +fig.basemap(region=[-19.5, 53, -37.5, 38], projection="M10c", frame="+n") |
36 | 30 |
|
37 | | -# First, we define the colormap to fill the polygons based on the "population" column. |
38 | | -pygmt.makecpt( |
39 | | - cmap="acton", |
40 | | - series=[gdf["population"].min(), gdf["population"].max(), 10], |
41 | | - continuous=True, |
42 | | - reverse=True, |
43 | | -) |
| 31 | +# First, we define the colormap to fill the polygons based on the "POP_EST" column. |
| 32 | +pygmt.makecpt(cmap="acton", series=(0, 100), reverse=True) |
44 | 33 |
|
45 | 34 | # Next, we plot the polygons and fill them using the defined colormap. The target column |
46 | 35 | # is defined by the aspatial parameter. |
47 | | -fig.plot( |
48 | | - data=gdf, |
49 | | - pen="0.3p,gray10", |
50 | | - fill="+z", |
51 | | - cmap=True, |
52 | | - aspatial="Z=population", |
53 | | -) |
| 36 | +fig.plot(data=africa, pen="0.8p,gray50", fill="+z", cmap=True, aspatial="Z=POP_EST") |
54 | 37 |
|
55 | 38 | # Add colorbar legend. |
56 | | -fig.colorbar(frame="x+lPopulation", position="jML+o-0.5c+w3.5c/0.2c") |
| 39 | +fig.colorbar(frame="x+lPopulation (millions)", position="jML+o2c/-2.5c+w5c+ef0.2c+ml") |
57 | 40 |
|
58 | 41 | fig.show() |
0 commit comments