This page was generated from notebooks/06_api.ipynb. Interactive online version: Binder badge

Overview of the mapclassify API

There are a number of ways to access the functionality in mapclassify

We first load the example dataset that we have seen earlier.

[1]:
import geopandas
import libpysal
import mapclassify

Current mapclassify version.

[2]:
mapclassify.__version__
[2]:
'2.4.2+107.gb97c316a.dirty'
[3]:
pth = libpysal.examples.get_path("columbus.shp")
gdf = geopandas.read_file(pth)
y = gdf.HOVAL
gdf.head()
[3]:
AREA PERIMETER COLUMBUS_ COLUMBUS_I POLYID NEIG HOVAL INC CRIME OPEN ... DISCBD X Y NSA NSB EW CP THOUS NEIGNO geometry
0 0.309441 2.440629 2 5 1 5 80.467003 19.531 15.725980 2.850747 ... 5.03 38.799999 44.070000 1.0 1.0 1.0 0.0 1000.0 1005.0 POLYGON ((8.62413 14.23698, 8.55970 14.74245, ...
1 0.259329 2.236939 3 1 2 1 44.567001 21.232 18.801754 5.296720 ... 4.27 35.619999 42.380001 1.0 1.0 0.0 0.0 1000.0 1001.0 POLYGON ((8.25279 14.23694, 8.28276 14.22994, ...
2 0.192468 2.187547 4 6 3 6 26.350000 15.956 30.626781 4.534649 ... 3.89 39.820000 41.180000 1.0 1.0 1.0 0.0 1000.0 1006.0 POLYGON ((8.65331 14.00809, 8.81814 14.00205, ...
3 0.083841 1.427635 5 2 4 2 33.200001 4.477 32.387760 0.394427 ... 3.70 36.500000 40.520000 1.0 1.0 0.0 0.0 1000.0 1002.0 POLYGON ((8.45950 13.82035, 8.47341 13.83227, ...
4 0.488888 2.997133 6 7 5 7 23.225000 11.252 50.731510 0.405664 ... 2.83 40.009998 38.000000 1.0 1.0 1.0 0.0 1000.0 1007.0 POLYGON ((8.68527 13.63952, 8.67758 13.72221, ...

5 rows × 21 columns

Original API (< 2.4.0)

[4]:
bp = mapclassify.BoxPlot(y)
bp
[4]:
BoxPlot

   Interval      Count
----------------------
( -inf, -0.70] |     0
(-0.70, 25.70] |    13
(25.70, 33.50] |    12
(33.50, 43.30] |    12
(43.30, 69.70] |     7
(69.70, 96.40] |     5

Extended API (>= 2.40)

Note the original API is still available so this extension keeps backwards compatibility.

[5]:
bp = mapclassify.classify(y, "box_plot")
bp
[5]:
BoxPlot

   Interval      Count
----------------------
( -inf, -0.70] |     0
(-0.70, 25.70] |    13
(25.70, 33.50] |    12
(33.50, 43.30] |    12
(43.30, 69.70] |     7
(69.70, 96.40] |     5
[6]:
type(bp)
[6]:
mapclassify.classifiers.BoxPlot
[7]:
q5 = mapclassify.classify(y, "quantiles", k=5)
q5
[7]:
Quantiles

   Interval      Count
----------------------
[17.90, 23.08] |    10
(23.08, 30.48] |    10
(30.48, 39.10] |     9
(39.10, 45.83] |    10
(45.83, 96.40] |    10

Robustness of the scheme argument

[8]:
mapclassify.classify(y, "boxPlot")
[8]:
BoxPlot

   Interval      Count
----------------------
( -inf, -0.70] |     0
(-0.70, 25.70] |    13
(25.70, 33.50] |    12
(33.50, 43.30] |    12
(43.30, 69.70] |     7
(69.70, 96.40] |     5
[9]:
mapclassify.classify(y, "Boxplot")
[9]:
BoxPlot

   Interval      Count
----------------------
( -inf, -0.70] |     0
(-0.70, 25.70] |    13
(25.70, 33.50] |    12
(33.50, 43.30] |    12
(43.30, 69.70] |     7
(69.70, 96.40] |     5
[10]:
mapclassify.classify(y, "Box_plot")
[10]:
BoxPlot

   Interval      Count
----------------------
( -inf, -0.70] |     0
(-0.70, 25.70] |    13
(25.70, 33.50] |    12
(33.50, 43.30] |    12
(43.30, 69.70] |     7
(69.70, 96.40] |     5
[13]:
mapclassify.classify(y, 'Std_Mean')
[13]:
StdMean

   Interval      Count
----------------------
( -inf,  1.50] |     0
( 1.50, 19.97] |     5
(19.97, 56.90] |    37
(56.90, 75.37] |     3
(75.37, 96.40] |     4
[15]:
mapclassify.classify(y, 'Std_Mean', anchor=True)
[15]:
StdMean

   Interval      Count
----------------------
[17.90, 19.97] |     5
(19.97, 38.44] |    24
(38.44, 56.90] |    13
(56.90, 75.37] |     3
(75.37, 93.83] |     3
(93.83, 96.40] |     1
[16]:
y.mean(), y.std(), y.min(), y.max()
[16]:
(38.43622446938775, 18.466069465206047, 17.9, 96.400002)
[ ]: