mapclassify.UserDefined¶
- class mapclassify.UserDefined(y, bins, lowest=None)[source]¶
User Specified Binning.
- Parameters:
- y
numpy.array
\((n,1)\), values to classify.
- bins
numpy.array
\((k,1)\), upper bounds of classes (have to be monotically increasing).
- lowest
float
(default
None
) Scalar minimum value of lowest class. Default is to set the minimum to
-inf
ify.min()
> first upper bound (which will override the default), otherwise minimum is set toy.min()
.
- y
- Attributes:
- yb
numpy.array
\((n,1)\), bin IDs for observations.
- bins
numpy.array
\((k,1)\), the upper bounds of each class.
- k
int
The number of classes.
- counts
numpy.array
\((k,1)\), the number of observations falling in each class.
- yb
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]
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:
- gdf
geopandas.GeoDataFrame
Contains the geometry column for the choropleth map.
- border_color
str
(default
‘lightgray’) Matplotlib color string to use for polygon border.
- border_width
float
(default
0.10) Width of polygon border.
- title
str
(default
None
) Title of map.
- cmap
str
(default
‘YlGnBu’) Matplotlib color string for color map to fill polygons.
- axis_onbool (
default
True
) Show coordinate axes.
- legend_kwds
dict
(default
{‘loc’: ‘lower right’, ‘fmt’:FMT}) Options for
ax.legend()
.- file_name
str
(default
None
) Name of file to save figure to.
- dpi
int
(default
600) Dots per inch for saved figure.
- ax
matplotlib.Axis
(default
None
) Axis on which to plot the choropleth. Default is
None
, which plots on the current figure.
- gdf
- Returns:
- f, ax
tuple
Matplotlib figure and axis on which the plot is made.
- f, ax
Notes
Requires
matplotlib
, and implicitly requires ageopandas.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:
- y
numpy.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.
- **kwargs
dict
Additional parameters that are passed to the
__init__
function of the class. For documentation, check the class constructor.
- y