From 493ef3484ec641bd898082ddbc4a577a258d0960 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Wed, 25 Dec 2024 21:01:19 +0800 Subject: [PATCH 1/4] Add 'geodatasets' as a dependency for docs and update the choropleth example --- .github/workflows/ci_docs.yml | 1 + ci/requirements/docs.yml | 1 + environment.yml | 1 + examples/gallery/maps/choropleth_map.py | 39 +++++++++++++------------ 4 files changed, 23 insertions(+), 19 deletions(-) diff --git a/.github/workflows/ci_docs.yml b/.github/workflows/ci_docs.yml index 749d5b42b00..a74d4fbfcd5 100644 --- a/.github/workflows/ci_docs.yml +++ b/.github/workflows/ci_docs.yml @@ -108,6 +108,7 @@ jobs: make pip python-build + geodatasets myst-nb panel sphinx>=6.2 diff --git a/ci/requirements/docs.yml b/ci/requirements/docs.yml index 84be526f47f..2a6fa860961 100644 --- a/ci/requirements/docs.yml +++ b/ci/requirements/docs.yml @@ -23,6 +23,7 @@ dependencies: - pip - python-build # Dev dependencies (building documentation) + - geodatasets - myst-nb - panel - sphinx>=6.2 diff --git a/environment.yml b/environment.yml index 620b1bad91b..ce30de4825c 100644 --- a/environment.yml +++ b/environment.yml @@ -35,6 +35,7 @@ dependencies: - pytest-doctestplus - pytest-mpl # Dev dependencies (building documentation) + - geodatasets - myst-nb - panel - sphinx>=6.2 diff --git a/examples/gallery/maps/choropleth_map.py b/examples/gallery/maps/choropleth_map.py index 6c43d24d3dd..c54a7f2e7f7 100644 --- a/examples/gallery/maps/choropleth_map.py +++ b/examples/gallery/maps/choropleth_map.py @@ -2,25 +2,27 @@ Choropleth map ============== -The :meth:`pygmt.Figure.plot` method allows us to plot geographical data such -as polygons which are stored in a :class:`geopandas.GeoDataFrame` object. Use -:func:`geopandas.read_file` to load data from any supported OGR format such as -a shapefile (.shp), GeoJSON (.geojson), geopackage (.gpkg), etc. You can also -use a full URL pointing to your desired data source. Then, pass the -:class:`geopandas.GeoDataFrame` as an argument to the ``data`` parameter of -:meth:`pygmt.Figure.plot`, and style the geometry using the ``pen`` parameter. -To fill the polygons based on a corresponding column you need to set -``fill="+z"`` as well as select the appropriate column using the ``aspatial`` -parameter as shown in the example below. +The :meth:`pygmt.Figure.plot` method allows us to plot geographical data such as +polygons which are stored in a :class:`geopandas.GeoDataFrame` object. Use +:func:`geopandas.read_file` to load data from any supported OGR format such as a +shapefile (.shp), GeoJSON (.geojson), geopackage (.gpkg), etc. You can also use a full +URL pointing to your desired data source. Then, pass the class:`geopandas.GeoDataFrame` +as an argument to the ``data`` parameter of :meth:`pygmt.Figure.plot`, and style the +geometry using the ``pen`` parameter. To fill the polygons based on a corresponding +column you need to set ``fill="+z"`` as well as select the appropriate column using the +``aspatial`` parameter as shown in the example below. """ # %% +import geodatasets import geopandas as gpd import pygmt -# Read polygon data using geopandas -gdf = gpd.read_file("https://geodacenter.github.io/data-and-lab/data/airbnb.zip") +# Read the example dataset provided by geodatasets. +gdf = gpd.read_file(geodatasets.get_path("geoda airbnb")) +gdf +# %% fig = pygmt.Figure() fig.basemap( @@ -29,11 +31,10 @@ frame="+tPopulation of Chicago", ) -# The dataset contains different attributes, here we select -# the "population" column to plot. +# 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. +# 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], @@ -41,8 +42,8 @@ reverse=True, ) -# Next, we plot the polygons and fill them using the defined colormap. -# The target column is defined by the aspatial parameter. +# 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", @@ -51,7 +52,7 @@ aspatial="Z=population", ) -# Add colorbar legend +# Add colorbar legend. fig.colorbar(frame="x+lPopulation", position="jML+o-0.5c+w3.5c/0.2c") fig.show() From df61734bb4e87cc7eb6651182ae56662c4584bab Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Wed, 25 Dec 2024 21:16:57 +0800 Subject: [PATCH 2/4] Fix styling --- examples/gallery/maps/choropleth_map.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/examples/gallery/maps/choropleth_map.py b/examples/gallery/maps/choropleth_map.py index c54a7f2e7f7..19376f3c61c 100644 --- a/examples/gallery/maps/choropleth_map.py +++ b/examples/gallery/maps/choropleth_map.py @@ -2,14 +2,14 @@ Choropleth map ============== -The :meth:`pygmt.Figure.plot` method allows us to plot geographical data such as -polygons which are stored in a :class:`geopandas.GeoDataFrame` object. Use -:func:`geopandas.read_file` to load data from any supported OGR format such as a -shapefile (.shp), GeoJSON (.geojson), geopackage (.gpkg), etc. You can also use a full -URL pointing to your desired data source. Then, pass the class:`geopandas.GeoDataFrame` -as an argument to the ``data`` parameter of :meth:`pygmt.Figure.plot`, and style the -geometry using the ``pen`` parameter. To fill the polygons based on a corresponding -column you need to set ``fill="+z"`` as well as select the appropriate column using the +The :meth:`pygmt.Figure.plot` method allows us to plot geographical data such as +polygons which are stored in a :class:`geopandas.GeoDataFrame` object. Use +:func:`geopandas.read_file` to load data from any supported OGR format such as a +shapefile (.shp), GeoJSON (.geojson), geopackage (.gpkg), etc. You can also use a full +URL pointing to your desired data source. Then, pass the class:`geopandas.GeoDataFrame` +as an argument to the ``data`` parameter of :meth:`pygmt.Figure.plot`, and style the +geometry using the ``pen`` parameter. To fill the polygons based on a corresponding +column you need to set ``fill="+z"`` as well as select the appropriate column using the ``aspatial`` parameter as shown in the example below. """ @@ -20,7 +20,7 @@ # Read the example dataset provided by geodatasets. gdf = gpd.read_file(geodatasets.get_path("geoda airbnb")) -gdf +print(gdf) # %% fig = pygmt.Figure() @@ -31,7 +31,7 @@ frame="+tPopulation of Chicago", ) -# The dataset contains different attributes, here we select the "population" column to +# 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. @@ -42,7 +42,7 @@ reverse=True, ) -# Next, we plot the polygons and fill them using the defined colormap. The target column +# 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, From f9fe25f0f06244964245835874fd34a825d5b866 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Wed, 25 Dec 2024 21:35:03 +0800 Subject: [PATCH 3/4] Use noqa --- 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 19376f3c61c..ff6abfbdf3c 100644 --- a/examples/gallery/maps/choropleth_map.py +++ b/examples/gallery/maps/choropleth_map.py @@ -20,7 +20,7 @@ # Read the example dataset provided by geodatasets. gdf = gpd.read_file(geodatasets.get_path("geoda airbnb")) -print(gdf) +gdf # noqa: B018 # %% fig = pygmt.Figure() From fb2abe40fe76635b714f1c6db0909f6a9b7e73b0 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Wed, 25 Dec 2024 21:40:55 +0800 Subject: [PATCH 4/4] Revert "Use noqa" This reverts commit f9fe25f0f06244964245835874fd34a825d5b866. --- 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 ff6abfbdf3c..19376f3c61c 100644 --- a/examples/gallery/maps/choropleth_map.py +++ b/examples/gallery/maps/choropleth_map.py @@ -20,7 +20,7 @@ # Read the example dataset provided by geodatasets. gdf = gpd.read_file(geodatasets.get_path("geoda airbnb")) -gdf # noqa: B018 +print(gdf) # %% fig = pygmt.Figure()