Skip to content
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

POC: Add Figure.choropleth to plot choropleth maps #2798

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

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()

Reminders

  • Run make format and make check to make sure the code follows the style guide.
  • Add tests for new features or tests that would have caught the bug that you're fixing.
  • Add new public functions/methods/classes to doc/api/index.rst.
  • Write detailed docstrings for all functions/methods.
  • If wrapping a new module, open a 'Wrap new GMT module' issue and submit reasonably-sized PRs.
  • If adding new functionality, add an example to docstrings or tutorials.
  • Use underscores (not hyphens) in names of Python files and directories.

@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.

----------
data : :class:`geopandas.GeoDataFrame`
The geopandas dataframe containing the geometry and data to plot.
fillcol : str
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fillcol : str
column : str

I feel fillcol is not the correct name for this parameter. Would simply use column, as it is also used in e.g. geopandas.

@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Brand new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants