{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import ipyleaflet \n", "import json \n", "import pandas as pd\n", "from ipywidgets import link, FloatSlider\n", "from branca.colormap import linear\n", "import random\n", "\n", "geo_json_data = json.load(open('us-states.json')) \n", "m = ipyleaflet.Map(center = (43,-100), zoom = 4)\n", "unemployment = pd.read_csv('US_Unemployment_Oct2012.csv')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "unemployment = dict(zip(unemployment['State'].tolist(), unemployment['Unemployment'].tolist()))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "layer = ipyleaflet.Choropleth(\n", " geo_data=geo_json_data,\n", " choro_data=unemployment,\n", " colormap=linear.YlOrRd_04,\n", " style={'fillOpacity': 0.8, 'dashArray': '5, 5'}\n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m.add_layer(layer)\n", "m" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# To add callback for style\n", "def compute_style(feature, colormap, choro_data):\n", " return {\n", " 'fillColor': colormap(choro_data),\n", " 'color': 'white',\n", " 'weight': random.randint(1, 3),\n", " }" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "layer.style_callback=compute_style" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "slider = FloatSlider(min=layer.value_min, max=layer.value_max, continuous_update=False)\n", "slider.value = layer.value_min\n", "link((slider, 'value'), (layer, 'value_min'))\n", "slider" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "linear.YlOrBr_04.to_step(10)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "linear.RdBu_11" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "linear.GnBu_09" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "layer.colormap = linear.RdBu_11" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from ipywidgets import Text, HTML\n", "from ipyleaflet import WidgetControl, GeoJSON \n", "\n", "\n", "html = HTML('''\n", "