geoplot.pointplot(df, projection=None, hue=None, categorical=False, scheme=None, k=5, cmap='Set1', vmin=None, vmax=None, scale=None, limits=(0.5, 2), scale_func=None, legend=False, legend_values=None, legend_labels=None, legend_kwargs=None, legend_var=None, figsize=(8, 6), extent=None, ax=None, **kwargs)¶A geospatial scatter plot. The simplest useful plot type available.
| Parameters: |
|
|---|---|
| Returns: | The axis object with the plot on it. |
| Return type: | AxesSubplot or GeoAxesSubplot instance |
Examples
The pointplot is a simple geospatial scatter plot,
with each point corresponding with one observation in your dataset. The expected input is a geopandas
GeoDataFrame with geometries consisting of shapely.geometry.Point entities. The simplest possible plot
can be made by specifying the input data (and, optionally, a projection).
import geoplot as gplt
import geoplot.crs as gcrs
gplt.pointplot(points)
The hue parameter accepts a data column and applies a colormap to the output.
gplt.pointplot(cities, projection=gcrs.AlbersEqualArea(), hue='ELEV_IN_FT')
The legend parameter toggles a legend.
gplt.pointplot(cities, projection=gcrs.AlbersEqualArea(), hue='ELEV_IN_FT', legend=True)
legend_labels specifies custom legend labels.
gplt.pointplot(cities, projection=gcrs.AlbersEqualArea(), hue='ELEV_IN_FT',
legend=True, legend_labels=list('ABCDE'))
pointplot will default to binning the observations in the given data column into five ordinal classes
containing equal numbers of observations - a quantile scheme. An
alternative binning scheme can be specified using the scheme parameter. Valid options are Quantile,
Equal_interval (bins will be of equal sizes but contain different numbers of observations),
and Fisher_jenks (an intermediate between the two).
gplt.pointplot(cities, projection=gcrs.AlbersEqualArea(), hue='ELEV_IN_FT',
legend=True, scheme='equal_interval')
If the variable of interest is already categorical, specify categorical=True to
use the labels in your dataset directly.
gplt.pointplot(collisions, projection=gcrs.AlbersEqualArea(), hue='BOROUGH',
legend=True, categorical=True)
Keyword arguments can be passed to the legend using the legend_kwargs argument. These arguments will be
passed to the underlying matplotlib.legend.Legend instance (ref). The loc and bbox_to_anchor
parameters are particularly useful for positioning the legend.
gplt.pointplot(collisions, projection=gcrs.AlbersEqualArea(), hue='BOROUGH',
categorical=True, legend=True, legend_kwargs={'loc': 'upper left'})
Additional arguments will be interpreted as keyword arguments to the underlying matplotlib.pyplot.scatter
instance (ref).
gplt.pointplot(collisions[collisions['BOROUGH'].notnull()], projection=gcrs.AlbersEqualArea(),
hue='BOROUGH', categorical=True,
legend=True, legend_kwargs={'loc': 'upper left'},
edgecolor='white', linewidth=0.5)
Change the number of bins by specifying an alternative k value.
gplt.pointplot(data, projection=gcrs.AlbersEqualArea(),
hue='var', k=8,
edgecolor='white', linewidth=0.5,
legend=True, legend_kwargs={'bbox_to_anchor': (1.25, 1.0)})
Adjust the colormap to any
colormap recognizable to matplotlib using the cmap parameter.
gplt.pointplot(data, projection=gcrs.AlbersEqualArea(),
hue='var', cmap='inferno', k=8,
edgecolor='white', linewidth=0.5,
legend=True, legend_kwargs={'bbox_to_anchor': (1.25, 1.0)})
To use a continuous colormap, explicitly specify k=None. Note that if legend=True,
a matplotlib.colorbar legend will be used (ref).
gplt.pointplot(data, projection=gcrs.AlbersEqualArea(),
hue='var', cmap='inferno', k=None,
edgecolor='white', linewidth=0.5,
legend=True, legend_kwargs={'bbox_to_anchor': (1.25, 1.0)})
scale provides an alternative or additional visual variable.
gplt.pointplot(collisions, projection=gcrs.AlbersEqualArea(),
scale='NUMBER OF PERSONS INJURED',
legend=True, legend_kwargs={'loc': 'upper left'})
The limits can be adjusted to fit your data using the limits parameter.
gplt.pointplot(collisions, projection=gcrs.AlbersEqualArea(),
scale='NUMBER OF PERSONS INJURED', limits=(0, 10),
legend=True, legend_kwargs={'loc': 'upper left'})
The default scaling function is linear: an observations at the midpoint of two others will be exactly midway
between them in size. To specify an alternative scaling function, use the scale_func parameter. This should
be a factory function of two variables which, when given the maximum and minimum of the dataset,
returns a scaling function which will be applied to the rest of the data. A demo is available in
the example gallery.
def trivial_scale(minval, maxval):
def scalar(val):
return 2
return scalar
gplt.pointplot(collisions, projection=gcrs.AlbersEqualArea(),
scale='NUMBER OF PERSONS INJURED', scale_func=trivial_scale,
legend=True, legend_kwargs={'loc': 'upper left'})
hue and scale can co-exist.
gplt.pointplot(collisions[collisions['BOROUGH'].notnull()],
projection=gcrs.AlbersEqualArea(),
hue='BOROUGH', categorical=True,
scale='NUMBER OF PERSONS INJURED', limits=(0, 10),
legend=True, legend_kwargs={'loc': 'upper left'})
In case more than one visual variable is used, control which one appears in the legend using legend_var.
gplt.pointplot(collisions[collisions['BOROUGH'].notnull()],
projection=gcrs.AlbersEqualArea(),
hue='BOROUGH', categorical=True,
scale='NUMBER OF PERSONS INJURED', limits=(0, 10),
legend=True, legend_kwargs={'loc': 'upper left'},
legend_var='scale')