{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Using `folium.colormap`\n", "\n", "**A few examples of how to use `folium.colormap` in choropleths.**" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "../folium/__init__.py\n", "0.2.0.dev\n" ] } ], "source": [ "import pandas as pd\n", "import json\n", "import sys\n", "sys.path.append('..')\n", "import folium\n", "print (folium.__file__)\n", "print (folium.__version__)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's load a GeoJSON file, and try to choropleth it." ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [], "source": [ "geo_json_data = json.load(open('us-states.json'))\n", "unemployment = pd.read_csv('./US_Unemployment_Oct2012.csv')\n", "unemployment_dict = unemployment.set_index('State')['Unemployment']" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Self-defined\n", "\n", "You can build a choropleth in using a self-defined function.\n", "It has to output an hexadecimal color string of the form `#RRGGBB` or `#RRGGBBAA`." ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def my_color_function(feature):\n", " \"\"\"Maps low values to green and hugh values to red.\"\"\"\n", " if unemployment_dict[feature['id']] > 6.5:\n", " return '#ff0000'\n", " else:\n", " return '#008000'" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", "
YlOrBr | |
Paired | |
PuOr | |
Pastel2 | |
Pastel1 | |
YlGn | |
PRGn | |
GnBu | |
YlGnBu | |
RdBu | |
RdGy | |
BuPu | |
RdYlGn | |
Accent | |
RdYlBu | |
Spectral | |
PuRd | |
BuGn | |
RdPu | |
Set3 | |
PuBuGn | |
Set2 | |
Set1 | |
BrBg | |
PuBu | |
Dark2 | |
OrRd | |
PiYG | |
YlOrRd |