|
| 1 | +""" |
| 2 | +choropleth - Plot a choropleth map. |
| 3 | +""" |
| 4 | + |
| 5 | +from pygmt._typing import GeoLike, PathLike |
| 6 | + |
| 7 | +__doctest_skip__ = ["choropleth"] |
| 8 | + |
| 9 | + |
| 10 | +def choropleth( |
| 11 | + self, |
| 12 | + data: GeoLike | PathLike, |
| 13 | + column: str, |
| 14 | + cmap: str | bool = True, |
| 15 | + **kwargs, |
| 16 | +): |
| 17 | + """ |
| 18 | + Plot a choropleth map. |
| 19 | +
|
| 20 | + This method is a thin wrapper around :meth:`pygmt.Figure.plot` that sets the |
| 21 | + appropriate parameters for creating a choropleth map by filling polygons based on |
| 22 | + values in a specified data column. It requires the input data to be a geo-like |
| 23 | + Python object that implements ``__geo_interface__`` (e.g. a |
| 24 | + :class:`geopandas.GeoDataFrame`), or an OGR_GMT file containing the geometry and |
| 25 | + data to plot. |
| 26 | +
|
| 27 | + Parameters |
| 28 | + ---------- |
| 29 | + data |
| 30 | + A geo-like Python object which implements ``__geo_interface__`` (e.g. a |
| 31 | + :class:`geopandas.GeoDataFrame` or :class:`shapely.geometry`), or an OGR_GMT |
| 32 | + file containing the geometry and data to plot. |
| 33 | + column |
| 34 | + The name of the data column to use for the fill. |
| 35 | + cmap |
| 36 | + The CPT to use for filling the polygons. If set to ``True``, the current CPT |
| 37 | + will be used. |
| 38 | + **kwargs |
| 39 | + Additional keyword arguments passed to :meth:`pygmt.Figure.plot`. |
| 40 | +
|
| 41 | + Examples |
| 42 | + -------- |
| 43 | + >>> import geopandas as gpd |
| 44 | + >>> import pygmt |
| 45 | + >>> world = gpd.read_file( |
| 46 | + ... "https://naciscdn.org/naturalearth/110m/cultural/ne_110m_admin_0_countries.zip" |
| 47 | + ... ) |
| 48 | + >>> world["POP_EST"] *= 1e-6 # Population in millions |
| 49 | +
|
| 50 | + >>> fig = pygmt.Figure() |
| 51 | + >>> fig.basemap(region=[-19.5, 53, -38, 37.5], projection="M15c", frame=True) |
| 52 | + >>> pygmt.makecpt(cmap="bilbao", series=(0, 270, 10), reverse=True) |
| 53 | + >>> fig.choropleth(world, column="POP_EST", pen="0.3p,gray10") |
| 54 | + >>> fig.colorbar(frame=True) |
| 55 | + >>> fig.show() |
| 56 | + """ |
| 57 | + self.plot( |
| 58 | + data=data, close=True, fill="+z", cmap=cmap, aspatial=f"Z={column}", **kwargs |
| 59 | + ) |
0 commit comments