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 501d862

@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature Brand new feature

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

3 participants