{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0.3.0.dev\n" ] } ], "source": [ "import os\n", "import folium\n", "\n", "print(folium.__version__)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Using `folium.colormap`\n", "\n", "**A few examples of how to use `folium.colormap` in choropleths.**\n", "\n", "Let's load a GeoJSON file, and try to choropleth it." ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import json\n", "import pandas as pd\n", "\n", "us_states = os.path.join('data', 'us-states.json')\n", "US_Unemployment_Oct2012 = os.path.join('data', 'US_Unemployment_Oct2012.csv')\n", "\n", "geo_json_data = json.load(open(us_states))\n", "unemployment = pd.read_csv(US_Unemployment_Oct2012)\n", "\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": [ "
| BrBg | |
| YlOrRd | |
| PuRd | |
| PiYG | |
| RdPu | |
| RdYlGn | |
| Set1 | |
| Pastel1 | |
| RdBu | |
| Accent | |
| RdGy | |
| OrRd | |
| Set3 | |
| Set2 | |
| BuGn | |
| Pastel2 | |
| PuOr | |
| Spectral | |
| Paired | |
| BuPu | |
| RdYlBu | |
| YlOrBr | |
| Dark2 | |
| GnBu | |
| YlGnBu | |
| PRGn | |
| PuBu | |
| PuBuGn | |
| YlGn |