-
Notifications
You must be signed in to change notification settings - Fork 235
Add Figure.choropleth to plot choropleth maps #2798
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Really like this idea, makes it much easier to generate a simple choropleth map. Will wait to continue working on #2796 until this PR is merged. |
Summary of changed imagesThis is an auto-generated report of images that have changed on the DVC remote
Image diff(s)Report last updated at commit 4b3dc43 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Adds a new Figure.choropleth convenience method for plotting choropleth maps, along with tests, documentation, and a gallery example.
Changes:
- Introduces
pygmt.src.choropleth.choroplethas a thin wrapper aroundFigure.plotto fill polygons based on a data column, and wires it intoFigureandpygmt.src. - Adds a new gallery example (
choropleth_map.py) demonstratingFigure.choroplethwith GeoPandas and Natural Earth data. - Adds a new image-comparison test (
test_choropleth) and corresponding baseline image for regression coverage.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| pygmt/src/choropleth.py | Defines the Figure.choropleth wrapper around Figure.plot, with documentation and examples for choropleth maps. |
| pygmt/src/init.py | Exposes the new choropleth method through the pygmt.src namespace for binding onto Figure. |
| pygmt/figure.py | Registers choropleth as a Figure method by importing it from pygmt.src. |
| pygmt/_typing.py | Introduces a GeoLike alias for geopandas.GeoDataFrame and incorporates it into TableLike for geo-related APIs. |
| pygmt/tests/test_choropleth.py | Adds an MPL image comparison test exercising Figure.choropleth with a GeoPandas world dataset. |
| pygmt/tests/baseline/test_choropleth.png.dvc | Adds the DVC-tracked baseline image metadata for the new choropleth regression test. |
| examples/gallery/maps/choropleth_map.py | Updates the gallery example to use Figure.choropleth and documents its usage with GeoPandas data. |
| doc/api/index.rst | Adds Figure.choropleth to the API autosummary under plotting map elements. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| data: GeoLike | PathLike, | ||
| column: str, | ||
| cmap: str | bool = True, | ||
| **kwargs, |
Copilot
AI
Jan 26, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The data parameter is annotated as GeoLike | PathLike, but GeoLike is currently defined only as geopandas.GeoDataFrame while the implementation and surrounding utilities (e.g., helpers.utils.data_kind and helpers.tempfile.tempfile_from_geojson) support any geo-like object implementing __geo_interface__ (including shapely geometries). This mismatch between the type hint and the documented behavior can confuse users and type checkers; consider broadening GeoLike to represent all supported geo-like inputs (e.g., via a protocol/union) or narrowing the docstring to match the actual annotated contract.
This reverts commit 12be8bd.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

Description of proposed changes
This PR adds the
Figure.choroplethmethod to plot choropleth maps.Implementations in other packages
Implementation in PyGMT
In PyGMT,
Figure.choroplethcan be implemented by wrapping theFigure.plotmethod (see the changes for details). It's API is designed like:in which,
datacan be :class:geopandas.GeoDataFrame, geo-like objects with__geo_interfaceor a OGR_GMT file.fillcolis the name of the column whose values will be used to assign the colors**kwargsare other parameters that can be passed toFigure.plot. Useful parameters are likecmap,pen,transparencyand more.Example
Preview: https://pygmt-dev--2798.org.readthedocs.build/en/2798/api/generated/pygmt.Figure.choropleth.html