In [1]:
import geopandas
from geopandas import read_file
In [2]:
import mapclassify
mapclassify.__version__
Out[2]:
In [3]:
import libpysal
libpysal.__version__
Out[3]:
In [5]:
libpysal.examples.available()
In [6]:
_ = libpysal.examples.load_example('South')
pth = libpysal.examples.get_path('south.shp')
In [7]:
df = read_file(pth)
In [8]:
%matplotlib inline
ax = df.plot(column='HR60', scheme='QUANTILES', k=4, \
cmap='BuPu', legend=True,
legend_kwds={'loc': 'center left', 'bbox_to_anchor':(1,0.5)})
In [9]:
labels = [t.get_text() for t in ax.get_legend().get_texts()]
labels
Out[9]:
In [10]:
q4 = mapclassify.Quantiles(df.HR60, k=4)
q4
Out[10]:
In [11]:
labels == q4.get_legend_classes()
Out[11]:
Note that in this case, the first interval is closed on the minimum value in the dataset. The other intervals have an open lower bound. This is now displayed in the legend.
In [12]:
ax = df.plot(column='HR60', scheme='QUANTILES', k=4, \
cmap='BuPu', legend=True,
legend_kwds={'loc': 'center left', 'bbox_to_anchor':(1,0.5)},
)
In [13]:
ax = df.plot(column='HR60', scheme='QUANTILES', k=4, \
cmap='BuPu', legend=True,
legend_kwds={'loc': 'center left', 'bbox_to_anchor':(1,0.5), 'fmt':"{:.4f}"})
In [14]:
ax = df.plot(column='HR60', scheme='QUANTILES', k=4, \
cmap='BuPu', legend=True,
legend_kwds={'loc': 'center left', 'bbox_to_anchor':(1,0.5), 'fmt':"{:.0f}"})
The new legends_kwds arg fmt
takes a string to set the numerical formatting.
In [15]:
ax = df.plot(column='HR60', scheme='BoxPlot', \
cmap='BuPu', legend=True,
legend_kwds={'loc': 'center left', 'bbox_to_anchor':(1,0.5),
'fmt': "{:.0f}"})
In [16]:
bp = mapclassify.BoxPlot(df.HR60)
bp
Out[16]:
In [17]:
bp.get_legend_classes(fmt="{:.0f}")
Out[17]:
In some classifiers the user should be aware that the lower (upper) bound of the first (last) interval is not equal to the minimum (maximum) of the attribute values. This is useful to detect extreme values and highly skewed distributions.
In [18]:
ax = df.plot(column='STATE_NAME', categorical=True, legend=True, \
legend_kwds={'loc': 'center left', 'bbox_to_anchor':(1,0.5),
'fmt': "{:.0f}"}) # fmt is ignored for categorical data
In [ ]: