Skip to content

Conversation

@seisman
Copy link
Member

@seisman seisman commented Nov 5, 2023

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

import geopandas as gpd
import pygmt

gdf = 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
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.

@seisman seisman added the feature Brand new feature label Dec 4, 2023
@seisman seisman modified the milestones: 0.11.0, 0.12.0 Dec 4, 2023
@seisman seisman removed this from the 0.12.0 milestone Feb 26, 2024
@seisman seisman modified the milestone: 0.13.0 Apr 22, 2024
@seisman seisman self-assigned this Oct 30, 2024
@github-actions
Copy link
Contributor

github-actions bot commented Nov 24, 2025

Summary of changed images

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

Status Path
added pygmt/tests/baseline/test_choropleth.png

Image diff(s)

Details

Added images

  • test_choropleth.png

Modified images

Path Old New

Report last updated at commit 4b3dc43

@seisman seisman changed the title POC: Add Figure.choropleth to plot choropleth maps Add Figure.choropleth to plot choropleth maps Nov 24, 2025
@seisman seisman added this to the 0.18.0 milestone Nov 24, 2025
@seisman seisman 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
@seisman seisman removed the needs review This PR has higher priority and needs review. label Nov 26, 2025
@seisman seisman modified the milestones: 0.18.0, 0.19.0 Dec 25, 2025
@seisman seisman added the needs review This PR has higher priority and needs review. label Jan 23, 2026
@seisman seisman requested a review from Copilot January 26, 2026 04:07
Copy link
Contributor

Copilot AI left a 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.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
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.

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

Copilot AI Jan 26, 2026

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.
@seisman seisman requested a review from a team January 29, 2026 22:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature Brand new feature needs review This PR has higher priority and needs review.

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

3 participants