In [19]:
import sys
import os
sys.path.append(os.path.abspath('..'))
import mapclassify as mc
import libpysal
import geopandas as gpd
import matplotlib.pyplot as plt

%matplotlib inline
In [20]:
df = gpd.read_file(libpysal.examples.get_path('south.shp'))

f, ax = plt.subplots(1, figsize=(9, 9)) tx.assign(cl=HR90LagQ10.yb).plot(column='cl', categorical=True, \ k=10, cmap='OrRd', linewidth=0.1, ax=ax, \ edgecolor='white', legend=True) ax.set_axis_off() plt.title("HR90 Spatial Lag Deciles")

In [23]:
hr60_q10 = mc.Quantiles(df['HR60'], k=10)
hr60_q10
/home/serge/anaconda3/envs/mapclassify/lib/python3.6/site-packages/scipy/stats/stats.py:1713: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.
  return np.add.reduce(sorted[indexer] * weights, axis=axis) / sumval
Out[23]:
                Quantiles                
 
Lower            Upper              Count
=========================================
         x[i] <=  0.000               180
 0.000 < x[i] <=  2.497               103
 2.497 < x[i] <=  3.927               141
 3.927 < x[i] <=  5.104               141
 5.104 < x[i] <=  6.245               141
 6.245 < x[i] <=  7.621               141
 7.621 < x[i] <=  9.188               141
 9.188 < x[i] <= 10.981               141
10.981 < x[i] <= 14.313               141
14.313 < x[i] <= 92.937               142
In [36]:
fig, ax = plt.subplots(figsize=(12,10), subplot_kw={'aspect':'equal'})
df.assign(cl=hr60_q10.yb).plot(column='cl', categorical=True, \
                              k=10, cmap='OrRd', linewidth=0.1, ax=ax, \
                              edgecolor='white', legend=True)
ax.set_axis_off()
plt.title('HR60 Deciles')
plt.savefig('hr60q10.png')
In [29]:
import numpy as np
np.random.seed(12345)
hr60_fj10 = mc.Fisher_Jenks(df['HR60'], k=10)
hr60_fj10
Out[29]:
               Fisher_Jenks              
 
Lower            Upper              Count
=========================================
         x[i] <=  1.707               216
 1.707 < x[i] <=  4.446               278
 4.446 < x[i] <=  7.082               287
 7.082 < x[i] <= 10.022               288
10.022 < x[i] <= 13.587               176
13.587 < x[i] <= 19.600               121
19.600 < x[i] <= 28.773                34
28.773 < x[i] <= 40.744                 8
40.744 < x[i] <= 53.305                 3
53.305 < x[i] <= 92.937                 1
In [37]:
fig, ax = plt.subplots(figsize=(12,10), subplot_kw={'aspect':'equal'})
df.assign(cl=hr60_fj10.yb).plot(column='cl', categorical=True, \
                              k=10, cmap='OrRd', linewidth=0.1, ax=ax, \
                              edgecolor='white', legend=True)
ax.set_axis_off()
plt.title('HR60 Fisher-Jenks')
plt.savefig('hr60fj10.png')
In [38]:
hr60_mb10 = mc.Maximum_Breaks(df['HR60'], k=10)


fig, ax = plt.subplots(figsize=(12,10), subplot_kw={'aspect':'equal'})
df.assign(cl=hr60_mb10.yb).plot(column='cl', categorical=True, \
                              k=10, cmap='OrRd', linewidth=0.1, ax=ax, \
                              edgecolor='white', legend=True)
ax.set_axis_off()
plt.title('HR60 Maximum Breaks')
plt.savefig('hr60mb10.png')
In [35]:
hr60_ea10 = mc.Equal_Interval(df['HR60'], k=10)


fig, ax = plt.subplots(figsize=(12,10), subplot_kw={'aspect':'equal'})
df.assign(cl=hr60_ea10.yb).plot(column='cl', categorical=True, \
                              k=10, cmap='OrRd', linewidth=0.1, ax=ax, \
                              edgecolor='white', legend=True)
ax.set_axis_off()
plt.title('HR60 Equal Interval')
Out[35]:
Text(0.5,1,'HR60 Equal Interval')
In [22]:
fig, ax = plt.subplots(figsize=(12,10), subplot_kw={'aspect':'equal'})
df.plot(column='HR60', ax=ax)
Out[22]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fc902e1ab38>
In [17]:
hr60_q5 = mc.Quantiles(df['HR60'], k=5)
/home/serge/anaconda3/envs/mapclassify/lib/python3.6/site-packages/scipy/stats/stats.py:1713: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.
  return np.add.reduce(sorted[indexer] * weights, axis=axis) / sumval
In [18]:
hr60_q5
Out[18]:
                Quantiles                
 
Lower            Upper              Count
=========================================
         x[i] <=  2.497               283
 2.497 < x[i] <=  5.104               282
 5.104 < x[i] <=  7.621               282
 7.621 < x[i] <= 10.981               282
10.981 < x[i] <= 92.937               283