{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Legends in mapclassify\n",
    "\n",
    "mapclassify allows for user defined formatting of legends"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'2.3.0'"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import mapclassify\n",
    "mapclassify.__version__"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "cal = mapclassify.load_example()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "q6 = mapclassify.Quantiles(cal, k=6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Quantiles                 \n",
       "\n",
       "     Interval        Count\n",
       "--------------------------\n",
       "[   0.13,    1.16] |    10\n",
       "(   1.16,    3.38] |    10\n",
       "(   3.38,    9.36] |     9\n",
       "(   9.36,   24.32] |    10\n",
       "(  24.32,   70.78] |     9\n",
       "(  70.78, 4111.45] |    10"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "q6"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The default is to use two decimal places for this dataset.\n",
    "If the user desires a list of strings with these values, the `get_legend_classes` method can be called\n",
    "which will return the strings with the default format:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['[   0.13,    1.16]',\n",
       " '(   1.16,    3.38]',\n",
       " '(   3.38,    9.36]',\n",
       " '(   9.36,   24.32]',\n",
       " '(  24.32,   70.78]',\n",
       " '(  70.78, 4111.45]']"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "q6.get_legend_classes()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "To set the legends to integers, an option can be passed into the method:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['[   0,    1]',\n",
       " '(   1,    3]',\n",
       " '(   3,    9]',\n",
       " '(   9,   24]',\n",
       " '(  24,   71]',\n",
       " '(  71, 4111]']"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "q6.get_legend_classes(fmt=\"{:.0f}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Note that this does not change the original object:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Quantiles                 \n",
       "\n",
       "     Interval        Count\n",
       "--------------------------\n",
       "[   0.13,    1.16] |    10\n",
       "(   1.16,    3.38] |    10\n",
       "(   3.38,    9.36] |     9\n",
       "(   9.36,   24.32] |    10\n",
       "(  24.32,   70.78] |     9\n",
       "(  70.78, 4111.45] |    10"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "q6"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The format can be changed on the object by calling the `set_fmt` method:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Quantiles           \n",
       "\n",
       "  Interval     Count\n",
       "--------------------\n",
       "[   0,    1] |    10\n",
       "(   1,    3] |    10\n",
       "(   3,    9] |     9\n",
       "(   9,   24] |    10\n",
       "(  24,   71] |     9\n",
       "(  71, 4111] |    10"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "q6.set_fmt(fmt=\"{:.0f}\")\n",
    "q6"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
