Mapping Tools¶
geopandas provides a high-level interface to the matplotlib
library for making maps. Mapping shapes is as easy as using the plot()
method on a GeoSeries
or GeoDataFrame
.
# Examine country GeoDataFrame
In [1]: world.head()
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-1-6e4c6b8ad2c1> in <module>()
----> 1 world.head()
NameError: name 'world' is not defined
# Basic plot, random colors
In [2]: world.plot();
Note that in general, any options one can pass to pyplot in matplotlib
(or style options that work for lines) can be passed to the plot()
method.
Chloropleth Maps¶
geopandas makes it easy to create Chloropleth maps (maps where the color of each shape is based on the value of an associated variable). Simply use the plot command with the column
argument set to the column whose values you want used to assign colors.
# Plot by GDP per capta
In [3]: world = world[(world.pop_est>0) & (world.name!="Antarctica")]
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-3-3d65aa1f3698> in <module>()
----> 1 world = world[(world.pop_est>0) & (world.name!="Antarctica")]
NameError: name 'world' is not defined
In [4]: world['gdp_per_cap'] = world.gdp_md_est / world.pop_est