Skip to content

Commit 071abac

Browse files
committed
Add Figure.choropleth to plot choropleth maps
1 parent f079866 commit 071abac

3 files changed

Lines changed: 22 additions & 0 deletions

File tree

pygmt/figure.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,7 @@ def _repr_html_(self):
520520

521521
from pygmt.src import ( # pylint: disable=import-outside-toplevel
522522
basemap,
523+
choropleth,
523524
coast,
524525
colorbar,
525526
contour,

pygmt/src/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from pygmt.src.basemap import basemap
77
from pygmt.src.binstats import binstats
88
from pygmt.src.blockm import blockmean, blockmedian, blockmode
9+
from pygmt.src.choropleth import choropleth
910
from pygmt.src.coast import coast
1011
from pygmt.src.colorbar import colorbar
1112
from pygmt.src.config import config

pygmt/src/choropleth.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
def choropleth(self, data, fillcol, cmap=True, **kwargs):
2+
"""
3+
Plot a choropleth map from a :class:`geopandas.GeoDataFrame` object.
4+
5+
Parameters
6+
----------
7+
data : :class:`geopandas.GeoDataFrame`
8+
The geopandas dataframe containing the geometry and data to plot.
9+
fillcol : str
10+
The column name of the data to use for the fill.
11+
cmap : str
12+
"""
13+
self.plot(
14+
data=data,
15+
close=True,
16+
fill="+z",
17+
cmap=cmap,
18+
aspatial=f"Z={fillcol}",
19+
**kwargs,
20+
)

0 commit comments

Comments
 (0)