|
2 | 2 | Choropleth map |
3 | 3 | ============== |
4 | 4 |
|
5 | | -The :meth:`pygmt.Figure.plot` method allows us to plot geographical data such |
6 | | -as polygons which are stored in a :class:`geopandas.GeoDataFrame` object. Use |
7 | | -:func:`geopandas.read_file` to load data from any supported OGR format such as |
8 | | -a shapefile (.shp), GeoJSON (.geojson), geopackage (.gpkg), etc. You can also |
9 | | -use a full URL pointing to your desired data source. Then, pass the |
10 | | -:class:`geopandas.GeoDataFrame` as an argument to the ``data`` parameter of |
11 | | -:meth:`pygmt.Figure.plot`, and style the geometry using the ``pen`` parameter. |
12 | | -To fill the polygons based on a corresponding column you need to set |
13 | | -``fill="+z"`` as well as select the appropriate column using the ``aspatial`` |
14 | | -parameter as shown in the example below. |
| 5 | +The :meth:`pygmt.Figure.choropleth` method allows us to plot geographical data such as |
| 6 | +polygons which are stored in a :class:`geopandas.GeoDataFrame` object or a OGR_GMT file. |
| 7 | +Use :func:`geopandas.read_file` to load data from any supported OGR formats such as a |
| 8 | +shapefile (.shp), GeoJSON (.geojson), geopackage (.gpkg), etc. You can also use a full |
| 9 | +URL pointing to your desired data source. Then, pass the :class:`geopandas.GeoDataFrame` |
| 10 | +as an argument to the ``data`` parameter of :meth:`pygmt.Figure.choropleth`, and style |
| 11 | +the geometry using the ``pen`` parameter. To fill the polygons based on a corresponding |
| 12 | +column you need to specify the colum name to the ``column`` parameter. |
15 | 13 | """ |
16 | 14 |
|
17 | 15 | # %% |
|
29 | 27 | frame="+tPopulation of Chicago", |
30 | 28 | ) |
31 | 29 |
|
32 | | -# The dataset contains different attributes, here we select |
33 | | -# the "population" column to plot. |
| 30 | +# The dataset contains different attributes, here we select the "population" column to |
| 31 | +# plot. |
34 | 32 |
|
35 | | -# First, we define the colormap to fill the polygons based on |
36 | | -# the "population" column. |
| 33 | +# First, we define the colormap to fill the polygons based on the "population" column. |
37 | 34 | pygmt.makecpt( |
38 | 35 | cmap="acton", |
39 | 36 | series=[gdf["population"].min(), gdf["population"].max(), 10], |
40 | 37 | continuous=True, |
41 | 38 | reverse=True, |
42 | 39 | ) |
43 | 40 |
|
44 | | -# Next, we plot the polygons and fill them using the defined colormap. |
45 | | -# The target column is defined by the aspatial parameter. |
46 | | -fig.plot( |
47 | | - data=gdf, |
48 | | - pen="0.3p,gray10", |
49 | | - fill="+z", |
50 | | - cmap=True, |
51 | | - aspatial="Z=population", |
52 | | -) |
| 41 | +# Next, we plot the polygons and fill them using the defined colormap. The target column |
| 42 | +# is specified by the `column` parameter. |
| 43 | +fig.choropleth(data=gdf, column="population", pen="0.3p,gray10", cmap=True) |
53 | 44 |
|
54 | 45 | # Add colorbar legend |
55 | 46 | fig.colorbar(frame="x+lPopulation", position="jML+o-0.5c+w3.5c/0.2c") |
|
0 commit comments