Skip to content

Add Figure.choropleth to plot choropleth maps - #2798

Merged
seisman merged 22 commits into
mainfrom
choropleth
Feb 2, 2026
Merged

Add Figure.choropleth to plot choropleth maps#2798
seisman merged 22 commits into
mainfrom
choropleth

Conversation

@seisman

@seismanseisman commented Nov 5, 2023

Copy link
Copy Markdown
Member

Description of proposed changes

This PR adds the Figure.choropleth method to plot choropleth maps.

Implementations in other packages

Implementation in PyGMT

In PyGMT, Figure.choropleth can be implemented by wrapping the Figure.plot method (see the changes for details). It's API is designed like:

Figure.choropleth(data, fill, **kwargs):

in which,

  • data can be :class:geopandas.GeoDataFrame, geo-like objects with __geo_interface or a OGR_GMT file.
  • fillcol is the name of the column whose values will be used to assign the colors
  • **kwargs are other parameters that can be passed to Figure.plot. Useful parameters are like cmap, pen, transparency and more.

Example

importgeopandasasgpdimportpygmtgdf=gpd.read_file("https://geodacenter.github.io/data-and-lab/data/airbnb.zip")
fig=pygmt.Figure()
pygmt.makecpt(
cmap="acton",
series=[gdf["population"].min(), gdf["population"].max(), 10],
continuous=True,
reverse=True,
)
fig.choropleth(gdf, fillcol="population", pen="0.3p,gray10")
fig.colorbar(frame=True)
fig.show()

Preview: https://pygmt-dev--2798.org.readthedocs.build/en/2798/api/generated/pygmt.Figure.choropleth.html

@michaelgrund

Copy link
Copy Markdown
Member

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.

Comment threadpygmt/src/choropleth.py Outdated
@github-actions

github-actionsBot commented Nov 24, 2025

Copy link
Copy Markdown
Contributor

Summary of changed images

This is an auto-generated report of images that have changed on the DVC remote

StatusPath
addedpygmt/tests/baseline/test_choropleth.png

Image diff(s)

Details

Added images

  • test_choropleth.png

Modified images

PathOldNew

Report last updated at commit 56eb346

@seismanseisman changed the title POC: Add Figure.choropleth to plot choropleth mapsAdd Figure.choropleth to plot choropleth mapsNov 24, 2025
@seismanseisman added this to the 0.18.0 milestone Nov 24, 2025
@seismanseisman added the needs review This PR has higher priority and needs review. label Nov 24, 2025
@seisman
seisman marked this pull request as ready for review November 24, 2025 10:28
@seismanseisman removed the needs review This PR has higher priority and needs review. label Nov 26, 2025
@seismanseisman modified the milestones: 0.18.0, 0.19.0Dec 25, 2025
@seismanseisman added the needs review This PR has higher priority and needs review. label Jan 23, 2026
@seisman
seisman requested a review from CopilotJanuary 26, 2026 04:07

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

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.choropleth as a thin wrapper around Figure.plot to fill polygons based on a data column, and wires it into Figure and pygmt.src.
  • Adds a new gallery example (choropleth_map.py) demonstrating Figure.choropleth with 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
FileDescription
pygmt/src/choropleth.pyDefines the Figure.choropleth wrapper around Figure.plot, with documentation and examples for choropleth maps.
pygmt/src/init.pyExposes the new choropleth method through the pygmt.src namespace for binding onto Figure.
pygmt/figure.pyRegisters choropleth as a Figure method by importing it from pygmt.src.
pygmt/_typing.pyIntroduces a GeoLike alias for geopandas.GeoDataFrame and incorporates it into TableLike for geo-related APIs.
pygmt/tests/test_choropleth.pyAdds an MPL image comparison test exercising Figure.choropleth with a GeoPandas world dataset.
pygmt/tests/baseline/test_choropleth.png.dvcAdds the DVC-tracked baseline image metadata for the new choropleth regression test.
examples/gallery/maps/choropleth_map.pyUpdates the gallery example to use Figure.choropleth and documents its usage with GeoPandas data.
doc/api/index.rstAdds Figure.choropleth to the API autosummary under plotting map elements.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +12 to +15
data: GeoLike | PathLike,
column: str,
cmap: str | bool = True,
**kwargs,

CopilotAIJan 26, 2026

Copy link

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.

Copilot uses AI. Check for mistakes.
Comment threadpygmt/src/choropleth.py Outdated
Comment threadpygmt/src/choropleth.py Outdated
Comment threadexamples/gallery/maps/choropleth_map.py Outdated
Comment threadexamples/gallery/maps/choropleth_map.py Outdated
Comment threadpygmt/src/choropleth.py
seismanand others added 15 commits January 29, 2026 14:11
@seisman
seisman requested a review from a teamJanuary 29, 2026 22:49
@seismanseisman added final review call This PR requires final review and approval from a second reviewer and removed needs review This PR has higher priority and needs review. labels Feb 1, 2026
@seisman
seisman merged commit 3ed8618 into mainFeb 2, 2026
24 of 26 checks passed
@seisman
seisman deleted the choropleth branch February 2, 2026 05:17
@seismanseisman removed the final review call This PR requires final review and approval from a second reviewer label Feb 2, 2026
@seismanseisman mentioned this pull request Feb 13, 2026
39 tasks
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

featureBrand new feature

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants

@seisman@michaelgrund