{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "Load GeoJSON as in [GeoJSON_and_choropleth.ipynb](https://github.com/python-visualization/folium/blob/master/examples/GeoJSON_and_choropleth.ipynb)." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "ExecuteTime": { "end_time": "2019-04-05T22:38:12.549432Z", "start_time": "2019-04-05T22:38:12.533446Z" } }, "outputs": [], "source": [ "import json\n", "\n", "import folium\n", "import requests\n", "\n", "\n", "url = (\n", " \"https://raw.githubusercontent.com/python-visualization/folium/master/examples/data\"\n", ")\n", "us_states = f\"{url}/us-states.json\"\n", "geo_json_data = json.loads(requests.get(us_states).text)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Using CustomPane to place labels above choropleth" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Map without custom pane" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "ExecuteTime": { "end_time": "2019-04-05T22:38:12.758314Z", "start_time": "2019-04-05T22:38:12.555438Z" } }, "outputs": [ { "data": { "text/html": [ "
Make this Notebook Trusted to load map: File -> Trust Notebook
" ], "text/plain": [ "" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "m = folium.Map([43, -100], zoom_start=4, tiles=\"stamentoner\")\n", "\n", "folium.GeoJson(geo_json_data).add_to(m)\n", "\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Map with custom pane" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "ExecuteTime": { "end_time": "2019-04-05T22:38:13.237039Z", "start_time": "2019-04-05T22:38:12.789303Z" } }, "outputs": [ { "data": { "text/html": [ "
Make this Notebook Trusted to load map: File -> Trust Notebook
" ], "text/plain": [ "" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "m = folium.Map([43, -100], zoom_start=4, tiles=\"stamentonerbackground\")\n", "\n", "folium.GeoJson(geo_json_data).add_to(m)\n", "\n", "folium.map.CustomPane(\"labels\").add_to(m)\n", "\n", "# Final layer associated to custom pane via the appropriate kwarg\n", "folium.TileLayer(\"stamentonerlabels\", pane=\"labels\").add_to(m)\n", "\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Same, but with a different tileset" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "ExecuteTime": { "end_time": "2019-04-05T22:38:13.543862Z", "start_time": "2019-04-05T22:38:13.241037Z" } }, "outputs": [ { "data": { "text/html": [ "
Make this Notebook Trusted to load map: File -> Trust Notebook
" ], "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "m = folium.Map([43, -100], zoom_start=4, tiles=\"CartoDBPositronNoLabels\")\n", "\n", "folium.GeoJson(geo_json_data).add_to(m)\n", "\n", "folium.map.CustomPane(\"labels\").add_to(m)\n", "\n", "# Final layer associated to custom pane via the appropriate kwarg\n", "folium.TileLayer(\"CartoDBPositronOnlyLabels\", pane=\"labels\").add_to(m)\n", "\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "More tile providers can be found at https://leaflet-extras.github.io/leaflet-providers/preview/." ] } ], "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.9.0" } }, "nbformat": 4, "nbformat_minor": 2 }