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)¶Geospatial scatter plot.
Parameters: |
|
---|---|
Returns: | The plot axis |
Return type: |
|
Examples
The pointplot
is a geospatial scatter plot representing
each observation in your dataset with a single point. It is simple and easily interpretable plot that is nearly
universally understood, making it an ideal choice for showing simple pointwise relationships between
observations.
The expected input is a GeoDataFrame
containing geometries of the shapely.geometry.Point
type. A
bare-bones pointplot goes thusly:
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. The legend
parameter
toggles a legend.
gplt.pointplot(cities, projection=gcrs.AlbersEqualArea(), hue='ELEV_IN_FT', legend=True)
The pointplot
binning methodology is controlled using by scheme` parameter. The default is quantile
,
which bins observations into classes of different sizes but the same numbers of observations. equal_interval
will creates bins that are the same size, but potentially containing different numbers of observations.
The more complicated fisher_jenks
scheme is an intermediate between the two.
gplt.pointplot(cities, projection=gcrs.AlbersEqualArea(), hue='ELEV_IN_FT',
legend=True, scheme='equal_interval')
Alternatively, your data may already be categorical. In that case specify categorical=True
instead.
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. Other additional arguments will be passed to the
underlying matplotlib
scatter plot.
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. Adjust the colormap using the cmap
parameter. To use a
continuous colormap, explicitly specify k=None
. Note that if legend=True
, a matplotlib
colorbar legend will be used.
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)})
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. 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')