Skip to content

Commit 41702d7

Browse files
authored
Add 'geodatasets' as a dependency for docs and update the choropleth example (#3719)
1 parent 48aeafa commit 41702d7

File tree

4 files changed

+23
-19
lines changed

4 files changed

+23
-19
lines changed

.github/workflows/ci_docs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ jobs:
108108
make
109109
pip
110110
python-build
111+
geodatasets
111112
myst-nb
112113
panel
113114
sphinx>=6.2

ci/requirements/docs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ dependencies:
2323
- pip
2424
- python-build
2525
# Dev dependencies (building documentation)
26+
- geodatasets
2627
- myst-nb
2728
- panel
2829
- sphinx>=6.2

environment.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ dependencies:
3535
- pytest-doctestplus
3636
- pytest-mpl
3737
# Dev dependencies (building documentation)
38+
- geodatasets
3839
- myst-nb
3940
- panel
4041
- sphinx>=6.2

examples/gallery/maps/choropleth_map.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,27 @@
22
Choropleth map
33
==============
44
5-
The :meth:`pygmt.Figure.plot` method allows us to plot geographical data such
6-
as polygons which are stored in a :class:`geopandas.GeoDataFrame` object. Use
7-
:func:`geopandas.read_file` to load data from any supported OGR format such as
8-
a shapefile (.shp), GeoJSON (.geojson), geopackage (.gpkg), etc. You can also
9-
use a full URL pointing to your desired data source. Then, pass the
10-
:class:`geopandas.GeoDataFrame` as an argument to the ``data`` parameter of
11-
:meth:`pygmt.Figure.plot`, and style the geometry using the ``pen`` parameter.
12-
To fill the polygons based on a corresponding column you need to set
13-
``fill="+z"`` as well as select the appropriate column using the ``aspatial``
14-
parameter as shown in the example below.
5+
The :meth:`pygmt.Figure.plot` method allows us to plot geographical data such as
6+
polygons which are stored in a :class:`geopandas.GeoDataFrame` object. Use
7+
:func:`geopandas.read_file` to load data from any supported OGR format such as a
8+
shapefile (.shp), GeoJSON (.geojson), geopackage (.gpkg), etc. You can also use a full
9+
URL pointing to your desired data source. Then, pass the class:`geopandas.GeoDataFrame`
10+
as an argument to the ``data`` parameter of :meth:`pygmt.Figure.plot`, and style the
11+
geometry using the ``pen`` parameter. To fill the polygons based on a corresponding
12+
column you need to set ``fill="+z"`` as well as select the appropriate column using the
13+
``aspatial`` parameter as shown in the example below.
1514
"""
1615

1716
# %%
17+
import geodatasets
1818
import geopandas as gpd
1919
import pygmt
2020

21-
# Read polygon data using geopandas
22-
gdf = gpd.read_file("https://geodacenter.github.io/data-and-lab/data/airbnb.zip")
21+
# Read the example dataset provided by geodatasets.
22+
gdf = gpd.read_file(geodatasets.get_path("geoda airbnb"))
23+
print(gdf)
2324

25+
# %%
2426
fig = pygmt.Figure()
2527

2628
fig.basemap(
@@ -29,20 +31,19 @@
2931
frame="+tPopulation of Chicago",
3032
)
3133

32-
# The dataset contains different attributes, here we select
33-
# the "population" column to plot.
34+
# The dataset contains different attributes, here we select the "population" column to
35+
# plot.
3436

35-
# First, we define the colormap to fill the polygons based on
36-
# the "population" column.
37+
# First, we define the colormap to fill the polygons based on the "population" column.
3738
pygmt.makecpt(
3839
cmap="acton",
3940
series=[gdf["population"].min(), gdf["population"].max(), 10],
4041
continuous=True,
4142
reverse=True,
4243
)
4344

44-
# Next, we plot the polygons and fill them using the defined colormap.
45-
# The target column is defined by the aspatial parameter.
45+
# Next, we plot the polygons and fill them using the defined colormap. The target column
46+
# is defined by the aspatial parameter.
4647
fig.plot(
4748
data=gdf,
4849
pen="0.3p,gray10",
@@ -51,7 +52,7 @@
5152
aspatial="Z=population",
5253
)
5354

54-
# Add colorbar legend
55+
# Add colorbar legend.
5556
fig.colorbar(frame="x+lPopulation", position="jML+o-0.5c+w3.5c/0.2c")
5657

5758
fig.show()

0 commit comments

Comments
 (0)