mapclassify.UserDefined

class mapclassify.UserDefined(y, bins, lowest=None)[source]

User Specified Binning.

Parameters:
ynumpy.array

\((n,1)\), values to classify.

binsnumpy.array

\((k,1)\), upper bounds of classes (have to be monotically increasing).

lowestfloat (default None)

Scalar minimum value of lowest class. Default is to set the minimum to -inf if y.min() > first upper bound (which will override the default), otherwise minimum is set to y.min().

Attributes:
ybnumpy.array

\((n,1)\), bin IDs for observations.

binsnumpy.array

\((k,1)\), the upper bounds of each class.

kint

The number of classes.

countsnumpy.array

\((k,1)\), the number of observations falling in each class.

Notes

If upper bound of user bins does not exceed max(y) we append an additional bin.

Examples

>>> import mapclassify
>>> cal = mapclassify.load_example()
>>> bins = [20, max(cal)]
>>> bins
[20, 4111.45]
>>> ud = mapclassify.UserDefined(cal, bins)
>>> ud.bins.tolist()
[20.0, 4111.45]
>>> ud.counts.tolist()
[37, 21]
>>> bins = [20, 30]
>>> ud = mapclassify.UserDefined(cal, bins)
>>> ud.bins.tolist()
[20.0, 30.0, 4111.45]
>>> ud.counts.tolist()
[37, 4, 17]
__init__(y, bins, lowest=None)[source]

Methods

__init__(y, bins[, lowest])

find_bin(x)

Sort input or inputs according to the current bin estimate.

get_adcm()

Absolute deviation around class median (ADCM).

get_fmt()

get_gadf()

Goodness of absolute deviation of fit.

get_legend_classes([fmt])

Format the strings for the classes on the legend.

get_tss()

Returns sum of squares over all class means.

make(*args, **kwargs)

Configure and create a classifier that will consume data and produce classifications, given the configuration options specified by this function.

plot(gdf[, border_color, border_width, ...])

Plot a mapclassifier object.

plot_histogram([color, linecolor, ...])

Plot histogram of y with bin values superimposed

set_fmt(fmt)

table()

update([y, inplace])

Add data or change classification parameters.

Attributes

fmt

plot(gdf, border_color='lightgray', border_width=0.1, title=None, legend=False, cmap='YlGnBu', axis_on=True, legend_kwds={'fmt': '{:.2f}', 'loc': 'lower right'}, file_name=None, dpi=600, ax=None)[source]

Plot a mapclassifier object.

Parameters:
gdfgeopandas.GeoDataFrame

Contains the geometry column for the choropleth map.

border_colorstr (default ‘lightgray’)

Matplotlib color string to use for polygon border.

border_widthfloat (default 0.10)

Width of polygon border.

titlestr (default None)

Title of map.

cmapstr (default ‘YlGnBu’)

Matplotlib color string for color map to fill polygons.

axis_onbool (default True)

Show coordinate axes.

legend_kwdsdict (default {‘loc’: ‘lower right’, ‘fmt’:FMT})

Options for ax.legend().

file_namestr (default None)

Name of file to save figure to.

dpiint (default 600)

Dots per inch for saved figure.

axmatplotlib.Axis (default None)

Axis on which to plot the choropleth. Default is None, which plots on the current figure.

Returns:
f, axtuple

Matplotlib figure and axis on which the plot is made.

Notes

Requires matplotlib, and implicitly requires a geopandas.GeoDataFrame as input.

Examples

>>> import libpysal
>>> import geopandas
>>> import mapclassify
>>> gdf = geopandas.read_file(libpysal.examples.get_path("columbus.shp"))
>>> q5 = mapclassify.Quantiles(gdf.CRIME)
>>> q5.plot(gdf)  
update(y=None, inplace=False, **kwargs)[source]

Add data or change classification parameters.

Parameters:
ynumpy.array (default None)

\((n,1)\), array of data to classify.

inplacebool (default False)

Whether to conduct the update in place or to return a copy estimated from the additional specifications.

**kwargsdict

Additional parameters that are passed to the __init__ function of the class. For documentation, check the class constructor.