geoplot.
voronoi
(df, projection=None, edgecolor='black', clip=None, hue=None, scheme=None, k=5, cmap='viridis', categorical=False, vmin=None, vmax=None, legend=False, legend_kwargs=None, legend_labels=None, extent=None, figsize=(8, 6), ax=None, **kwargs)¶Geospatial Voronoi diagram.
Parameters: |
|
---|---|
Returns: | The axis object with the plot on it. |
Return type: | AxesSubplot or GeoAxesSubplot instance |
Examples
The neighborhood closest to a point in space is known as its Voronoi region. Every point in a dataset has a Voronoi region, which may be either a closed polygon (for inliers) or open infinite region (for points on the edge of the distribution). A Voronoi diagram works by dividing a space filled with points into such regions and plotting the result. Voronoi plots allow efficient assessmelt of the density of points in different spaces, and when combined with a colormap can be quite informative of overall trends in the dataset.
The geoplot
voronoi
is a spatially aware application of this technique. It compares well with the more
well-known choropleth
, which has the advantage of using meaningful regions, but the disadvantage of having
defined those regions beforehand. voronoi
has fewer requirements and may perform better when the number of
observations is small. Compare also with the quadtree technique available in aggplot
.
A basic voronoi
specified data and, optionally, a projection. We overlay geometry to aid interpretability.
ax = gplt.voronoi(injurious_collisions.head(1000))
gplt.polyplot(boroughs, ax=ax)
hue
parameterizes the color, and cmap
controls the colormap.
ax = gplt.voronoi(injurious_collisions.head(1000), hue='NUMBER OF PERSONS INJURED', cmap='Reds')
gplt.polyplot(boroughs, ax=ax)
Add a clip
of iterable geometries to trim the voronoi
against local geography.
ax = gplt.voronoi(injurious_collisions.head(1000), hue='NUMBER OF PERSONS INJURED', cmap='Reds',
clip=boroughs.geometry)
gplt.polyplot(boroughs, ax=ax)
legend
adds a a matplotlib
Legend. This can be tuned even further using the
legend_kwargs
argument. Other keyword parameters are passed to the underlying matplotlib
Polygon patches.
ax = gplt.voronoi(injurious_collisions.head(1000), hue='NUMBER OF PERSONS INJURED', cmap='Reds',
clip=boroughs.geometry,
legend=True, legend_kwargs={'loc': 'upper left'},
linewidth=0.5, edgecolor='white',
)
gplt.polyplot(boroughs, ax=ax)
Change the number of bins by specifying an alternative k
value. To use a continuous colormap, explicitly
specify k=None
. You can change the binning sceme with scheme
. 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.
ax = gplt.voronoi(injurious_collisions.head(1000),
hue='NUMBER OF PERSONS INJURED', cmap='Reds', k=5, scheme='fisher_jenks',
clip=boroughs.geometry,
legend=True, legend_kwargs={'loc': 'upper left'},
linewidth=0.5, edgecolor='white',
)
gplt.polyplot(boroughs, ax=ax)
If your variable of interest is already categorical, specify categorical=True
to
use the labels in your dataset directly.
ax = gplt.voronoi(injurious_collisions.head(1000), hue='NUMBER OF PERSONS INJURED', cmap='Reds',
edgecolor='white', clip=boroughs.geometry,
linewidth=0.5, categorical=True
)
gplt.polyplot(boroughs, linewidth=1, ax=ax)