From f601232509bffdb86a534045bfa466c7bbe07721 Mon Sep 17 00:00:00 2001
From: Conengmo <33519926+Conengmo@users.noreply.github.com>
Date: Wed, 6 Sep 2023 10:48:20 +0200
Subject: [PATCH] batch 1
---
examples/CheckZorder.ipynb | 4 +-
...th Jenks natural breaks optimization.ipynb | 4 +-
examples/ClickEvents.ipynb | 503 +-----
examples/Colormaps.ipynb | 1112 +-----------
examples/ContinuousWorld.ipynb | 113 +-
examples/ControlScale.ipynb | 41 +-
examples/CustomIcon.ipynb | 52 +-
examples/CustomPanes.ipynb | 170 +-
examples/FeatureGroup.ipynb | 40 +-
examples/Features.ipynb | 1552 +----------------
examples/FitOverlays.ipynb | 500 +-----
examples/FloatImage.ipynb | 40 +-
examples/GeoJSONMarker.ipynb | 346 +---
examples/GeoJSONWithoutTitles.ipynb | 146 +-
examples/GeoJSON_and_choropleth.ipynb | 877 +---------
examples/GeoJsonPopupAndTooltip.ipynb | 955 +---------
examples/GeodedeticImageOverlay.ipynb | 202 +--
examples/Geopandas_and_geo_interface.ipynb | 373 +---
examples/Heatmap.ipynb | 47 +-
examples/flask_example.py | 94 +-
20 files changed, 109 insertions(+), 7062 deletions(-)
diff --git a/examples/CheckZorder.ipynb b/examples/CheckZorder.ipynb
index f2b7aed4a..d502fb9c0 100644
--- a/examples/CheckZorder.ipynb
+++ b/examples/CheckZorder.ipynb
@@ -3,8 +3,8 @@
{
"cell_type": "markdown",
"source": [
- "This notebook has been removed.\n",
- "See the current documentation at https://python-visualization.github.io/folium/latest/."
+ "We've updated our documentation and removed this notebook.\n",
+ "You can find the current documentation at https://python-visualization.github.io/folium/latest/."
],
"metadata": {
"collapsed": false,
diff --git a/examples/Choropleth with Jenks natural breaks optimization.ipynb b/examples/Choropleth with Jenks natural breaks optimization.ipynb
index 57643e08d..82e89ed81 100644
--- a/examples/Choropleth with Jenks natural breaks optimization.ipynb
+++ b/examples/Choropleth with Jenks natural breaks optimization.ipynb
@@ -3,8 +3,8 @@
{
"cell_type": "markdown",
"source": [
- "This notebook has been moved to \n",
- "https://python-visualization.github.io/folium/latest/advanced_guide/choropleth%20with%20Jenks%20natural%20breaks%20optimization.html."
+ "We've updated our documentation. You can find the new version of this notebook here:\n",
+ "https://python-visualization.github.io/folium/latest/advanced_guide/choropleth%20with%20Jenks%20natural%20breaks%20optimization.html"
],
"metadata": {
"collapsed": false
diff --git a/examples/ClickEvents.ipynb b/examples/ClickEvents.ipynb
index 3f5d2aebf..f527c8df3 100644
--- a/examples/ClickEvents.ipynb
+++ b/examples/ClickEvents.ipynb
@@ -1,505 +1,16 @@
{
"cells": [
- {
- "cell_type": "code",
- "execution_count": 1,
- "id": "6b3009b4",
- "metadata": {},
- "outputs": [],
- "source": [
- "import folium\n",
- "from folium.features import ClickForLatLng, ClickForMarker, LatLngPopup"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "df990137",
- "metadata": {},
- "source": [
- "#### `ClickForMarker` Lets you create markers on each click"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 2,
- "id": "55e317b4",
- "metadata": {},
- "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": [
- "folium.Map().add_child(ClickForMarker())"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "ad4a4cfc",
- "metadata": {},
- "source": [
- "*Click on the map to see the effects*"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "9cecff8c",
- "metadata": {},
- "source": [
- "You can customize the popup by providing a string, an IFrame object or an Html object. You can include the latitude and longitude of the marker by using `${lat}` and `${lng}`."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 3,
- "id": "7755ae9b",
- "metadata": {},
- "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": [
- "folium.Map().add_child(ClickForMarker(\"Lat: ${lat}Lon: ${lng}\"))"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "45c985b4",
- "metadata": {},
- "source": [
- "*Click on the map to see the effects*"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "76e5e9b9",
- "metadata": {},
- "source": [
- "#### `LatLngPopup` lets you create a simple popup at each click"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 4,
- "id": "205a9f4a",
- "metadata": {},
- "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": [
- "folium.Map().add_child(LatLngPopup())"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "c7ed398a",
- "metadata": {},
- "source": [
- "*Click on the map to see the effects*"
- ]
- },
{
"cell_type": "markdown",
- "id": "74717849",
- "metadata": {},
- "source": [
- "#### `ClickForLatLng` lets you copy coordinates to your browser clipboard"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 5,
- "id": "5c564b6b",
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "Make this Notebook Trusted to load map: File -> Trust Notebook
"
- ],
- "text/plain": [
- ""
- ]
- },
- "execution_count": 5,
- "metadata": {},
- "output_type": "execute_result"
+ "id": "6b3009b4",
+ "metadata": {
+ "pycharm": {
+ "name": "#%% md\n"
}
- ],
- "source": [
- "folium.Map().add_child(ClickForLatLng(format_str='\"[\" + lat + \",\" + lng + \"]\"'))"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "8f2809bd",
- "metadata": {},
- "source": [
- "*Click on the map to see the effects*"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "f90c1e9b",
- "metadata": {},
+ },
"source": [
- "If you want to collect back the information in python, you may (install and) import the [clipboard](https://github.com/terryyin/clipboard) library :\n",
- "\n",
- "```python\n",
- "> import clipboard\n",
- "> clipboard.paste()\n",
- "```\n",
- "```\n",
- "[-43.580391,-123.824467]\n",
- "```"
+ "We've updated our documentation. You can find the new version of this notebook here:\n",
+ "https://python-visualization.github.io/folium/latest/user_guide/features/click_related_classes.html"
]
}
],
diff --git a/examples/Colormaps.ipynb b/examples/Colormaps.ipynb
index 1f195f39c..e42b8ea25 100644
--- a/examples/Colormaps.ipynb
+++ b/examples/Colormaps.ipynb
@@ -2,1115 +2,13 @@
"cells": [
{
"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": 1,
- "metadata": {},
- "outputs": [],
- "source": [
- "import json\n",
- "\n",
- "import folium\n",
- "import pandas as pd\n",
- "import requests\n",
- "\n",
- "\n",
- "url = (\n",
- " \"https://raw.githubusercontent.com/python-visualization/folium/main/examples/data\"\n",
- ")\n",
- "us_states = f\"{url}/us-states.json\"\n",
- "US_Unemployment_Oct2012 = f\"{url}/US_Unemployment_Oct2012.csv\"\n",
- "\n",
- "geo_json_data = json.loads(requests.get(us_states).text)\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": 2,
- "metadata": {},
- "outputs": [],
- "source": [
- "def my_color_function(feature):\n",
- " \"\"\"Maps low values to green and high values to red.\"\"\"\n",
- " if unemployment_dict[feature[\"id\"]] > 6.5:\n",
- " return \"#ff0000\"\n",
- " else:\n",
- " return \"#008000\""
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 3,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "Make this Notebook Trusted to load map: File -> Trust Notebook
"
- ],
- "text/plain": [
- ""
- ]
- },
- "execution_count": 3,
- "metadata": {},
- "output_type": "execute_result"
- }
+ "We've updated our documentation. You can find the new version of this notebook here:\n",
+ "https://python-visualization.github.io/folium/latest/advanced_guide/colormaps.html"
],
- "source": [
- "m = folium.Map([43, -100], tiles=\"cartodbpositron\", zoom_start=4)\n",
- "\n",
- "folium.GeoJson(\n",
- " geo_json_data,\n",
- " style_function=lambda feature: {\n",
- " \"fillColor\": my_color_function(feature),\n",
- " \"color\": \"black\",\n",
- " \"weight\": 2,\n",
- " \"dashArray\": \"5, 5\",\n",
- " },\n",
- ").add_to(m)\n",
- "\n",
- "m"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "## StepColormap\n",
- "\n",
- "But to help you define your colormap, we've embedded `StepColormap` in `folium.colormap`.\n",
- "\n",
- "You can simply define the colors you want, and the `index` (*thresholds*) that correspond."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 4,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "3 10 "
- ],
- "text/plain": [
- ""
- ]
- },
- "execution_count": 4,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "import branca.colormap as cm\n",
- "\n",
- "step = cm.StepColormap(\n",
- " [\"green\", \"yellow\", \"red\"], vmin=3, vmax=10, index=[3, 4, 8, 10], caption=\"step\"\n",
- ")\n",
- "\n",
- "step"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 5,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "Make this Notebook Trusted to load map: File -> Trust Notebook
"
- ],
- "text/plain": [
- ""
- ]
- },
- "execution_count": 5,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "m = folium.Map([43, -100], tiles=\"cartodbpositron\", zoom_start=4)\n",
- "\n",
- "folium.GeoJson(\n",
- " geo_json_data,\n",
- " style_function=lambda feature: {\n",
- " \"fillColor\": step(unemployment_dict[feature[\"id\"]]),\n",
- " \"color\": \"black\",\n",
- " \"weight\": 2,\n",
- " \"dashArray\": \"5, 5\",\n",
- " },\n",
- ").add_to(m)\n",
- "\n",
- "m"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "If you specify no index, colors will be set uniformly."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 6,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "0.0 1.0 "
- ],
- "text/plain": [
- ""
- ]
- },
- "execution_count": 6,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "cm.StepColormap([\"r\", \"y\", \"g\", \"c\", \"b\", \"m\"])"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "## LinearColormap\n",
- "\n",
- "But sometimes, you would prefer to have a *continuous* set of colors. This can be done by `LinearColormap`."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 7,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "3 10 "
- ],
- "text/plain": [
- ""
- ]
- },
- "execution_count": 7,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "linear = cm.LinearColormap([\"green\", \"yellow\", \"red\"], vmin=3, vmax=10)\n",
- "\n",
- "linear"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 8,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "Make this Notebook Trusted to load map: File -> Trust Notebook
"
- ],
- "text/plain": [
- ""
- ]
- },
- "execution_count": 8,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "m = folium.Map([43, -100], tiles=\"cartodbpositron\", zoom_start=4)\n",
- "\n",
- "folium.GeoJson(\n",
- " geo_json_data,\n",
- " style_function=lambda feature: {\n",
- " \"fillColor\": linear(unemployment_dict[feature[\"id\"]]),\n",
- " \"color\": \"black\",\n",
- " \"weight\": 2,\n",
- " \"dashArray\": \"5, 5\",\n",
- " },\n",
- ").add_to(m)\n",
- "\n",
- "m"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "Again, you can set the `index` if you want something irregular."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 9,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "0.0 1.0 "
- ],
- "text/plain": [
- ""
- ]
- },
- "execution_count": 9,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "cm.LinearColormap([\"red\", \"orange\", \"yellow\", \"green\"], index=[0, 0.1, 0.9, 1.0])"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "If you want to transform a linear map into a *step* one, you can use the method `to_step`."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 10,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "3.0 10.0 "
- ],
- "text/plain": [
- ""
- ]
- },
- "execution_count": 10,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "linear.to_step(6)"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "You can also use more sophisticated rules to create the thresholds."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 11,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "31 100 "
- ],
- "text/plain": [
- ""
- ]
- },
- "execution_count": 11,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "linear.to_step(\n",
- " n=6,\n",
- " data=[30.6, 50, 51, 52, 53, 54, 55, 60, 70, 100],\n",
- " method=\"quantiles\",\n",
- " round_method=\"int\",\n",
- ")"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "And the opposite is also possible with `to_linear`."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 12,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "3 10 "
- ],
- "text/plain": [
- ""
- ]
- },
- "execution_count": 12,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "step.to_linear()"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "## Built-in\n",
- "\n",
- "For convenience, we provide a (small) set of built-in linear colormaps, in `folium.colormap.linear`."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 13,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "0.0 1.0 "
- ],
- "text/plain": [
- ""
- ]
- },
- "execution_count": 13,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "cm.linear.OrRd_09"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "You can also use them to generate regular `StepColormap`."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 14,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "0.0 1.0 "
- ],
- "text/plain": [
- ""
- ]
- },
- "execution_count": 14,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "cm.linear.PuBuGn_09.to_step(12)"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "Of course, you may need to scale the colormaps to your bounds. This is doable with `.scale`."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 15,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "3 12 "
- ],
- "text/plain": [
- ""
- ]
- },
- "execution_count": 15,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "cm.linear.YlGnBu_09.scale(3, 12)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 16,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "5 100 "
- ],
- "text/plain": [
- ""
- ]
- },
- "execution_count": 16,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "cm.linear.RdGy_11.to_step(10).scale(5, 100)"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "At last, if you want to check them all, simply ask for `linear` in the notebook."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 17,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- " \n",
- " \n",
- " viridis 0.0 1.0 \n",
- " \n",
- " Pastel1_03 0.0 1.0 \n",
- " \n",
- " Pastel1_05 0.0 1.0 \n",
- " \n",
- " Pastel1_04 0.0 1.0 \n",
- " \n",
- " Pastel1_07 0.0 1.0 \n",
- " \n",
- " YlOrRd_04 0.0 1.0 \n",
- " \n",
- " Pastel1_09 0.0 1.0 \n",
- " \n",
- " Pastel1_08 0.0 1.0 \n",
- " \n",
- " Spectral_07 0.0 1.0 \n",
- " \n",
- " RdYlBu_05 0.0 1.0 \n",
- " \n",
- " PuBuGn_03 0.0 1.0 \n",
- " \n",
- " Set1_08 0.0 1.0 \n",
- " \n",
- " PuBuGn_05 0.0 1.0 \n",
- " \n",
- " PuBuGn_04 0.0 1.0 \n",
- " \n",
- " PuBuGn_07 0.0 1.0 \n",
- " \n",
- " PuBuGn_06 0.0 1.0 \n",
- " \n",
- " PuBuGn_09 0.0 1.0 \n",
- " \n",
- " PuBuGn_08 0.0 1.0 \n",
- " \n",
- " YlOrBr_04 0.0 1.0 \n",
- " \n",
- " YlOrBr_05 0.0 1.0 \n",
- " \n",
- " Set1_07 0.0 1.0 \n",
- " \n",
- " YlOrBr_03 0.0 1.0 \n",
- " \n",
- " Set1_05 0.0 1.0 \n",
- " \n",
- " YlOrRd_03 0.0 1.0 \n",
- " \n",
- " PuOr_06 0.0 1.0 \n",
- " \n",
- " PuOr_07 0.0 1.0 \n",
- " \n",
- " PuOr_04 0.0 1.0 \n",
- " \n",
- " PuOr_05 0.0 1.0 \n",
- " \n",
- " PuOr_03 0.0 1.0 \n",
- " \n",
- " Purples_09 0.0 1.0 \n",
- " \n",
- " Set2_06 0.0 1.0 \n",
- " \n",
- " RdYlBu_11 0.0 1.0 \n",
- " \n",
- " PuOr_08 0.0 1.0 \n",
- " \n",
- " PuOr_09 0.0 1.0 \n",
- " \n",
- " Paired_03 0.0 1.0 \n",
- " \n",
- " RdBu_03 0.0 1.0 \n",
- " \n",
- " RdYlBu_10 0.0 1.0 \n",
- " \n",
- " Paired_07 0.0 1.0 \n",
- " \n",
- " Paired_06 0.0 1.0 \n",
- " \n",
- " Paired_05 0.0 1.0 \n",
- " \n",
- " Paired_04 0.0 1.0 \n",
- " \n",
- " Paired_09 0.0 1.0 \n",
- " \n",
- " Paired_08 0.0 1.0 \n",
- " \n",
- " RdGy_03 0.0 1.0 \n",
- " \n",
- " PiYG_04 0.0 1.0 \n",
- " \n",
- " Accent_03 0.0 1.0 \n",
- " \n",
- " BuGn_08 0.0 1.0 \n",
- " \n",
- " BuGn_09 0.0 1.0 \n",
- " \n",
- " BuGn_04 0.0 1.0 \n",
- " \n",
- " BuGn_05 0.0 1.0 \n",
- " \n",
- " BuGn_06 0.0 1.0 \n",
- " \n",
- " BuGn_07 0.0 1.0 \n",
- " \n",
- " BuGn_03 0.0 1.0 \n",
- " \n",
- " YlGnBu_07 0.0 1.0 \n",
- " \n",
- " YlGnBu_06 0.0 1.0 \n",
- " \n",
- " YlGnBu_05 0.0 1.0 \n",
- " \n",
- " YlGnBu_04 0.0 1.0 \n",
- " \n",
- " YlGnBu_03 0.0 1.0 \n",
- " \n",
- " RdBu_06 0.0 1.0 \n",
- " \n",
- " RdBu_05 0.0 1.0 \n",
- " \n",
- " RdBu_04 0.0 1.0 \n",
- " \n",
- " Accent_08 0.0 1.0 \n",
- " \n",
- " RdBu_09 0.0 1.0 \n",
- " \n",
- " RdBu_08 0.0 1.0 \n",
- " \n",
- " Set2_04 0.0 1.0 \n",
- " \n",
- " YlGnBu_09 0.0 1.0 \n",
- " \n",
- " YlGnBu_08 0.0 1.0 \n",
- " \n",
- " Blues_08 0.0 1.0 \n",
- " \n",
- " Blues_09 0.0 1.0 \n",
- " \n",
- " RdPu_09 0.0 1.0 \n",
- " \n",
- " RdPu_08 0.0 1.0 \n",
- " \n",
- " Set3_07 0.0 1.0 \n",
- " \n",
- " Set3_06 0.0 1.0 \n",
- " \n",
- " RdPu_05 0.0 1.0 \n",
- " \n",
- " RdPu_04 0.0 1.0 \n",
- " \n",
- " RdPu_07 0.0 1.0 \n",
- " \n",
- " RdPu_06 0.0 1.0 \n",
- " \n",
- " Blues_06 0.0 1.0 \n",
- " \n",
- " Blues_07 0.0 1.0 \n",
- " \n",
- " RdPu_03 0.0 1.0 \n",
- " \n",
- " Blues_05 0.0 1.0 \n",
- " \n",
- " Paired_10 0.0 1.0 \n",
- " \n",
- " Paired_11 0.0 1.0 \n",
- " \n",
- " Paired_12 0.0 1.0 \n",
- " \n",
- " PuBu_06 0.0 1.0 \n",
- " \n",
- " PuBu_07 0.0 1.0 \n",
- " \n",
- " PuBu_04 0.0 1.0 \n",
- " \n",
- " PuBu_05 0.0 1.0 \n",
- " \n",
- " PuRd_05 0.0 1.0 \n",
- " \n",
- " PuBu_03 0.0 1.0 \n",
- " \n",
- " PuRd_07 0.0 1.0 \n",
- " \n",
- " PuRd_06 0.0 1.0 \n",
- " \n",
- " PuRd_09 0.0 1.0 \n",
- " \n",
- " PuRd_08 0.0 1.0 \n",
- " \n",
- " Set2_07 0.0 1.0 \n",
- " \n",
- " PuBu_08 0.0 1.0 \n",
- " \n",
- " PuBu_09 0.0 1.0 \n",
- " \n",
- " RdBu_10 0.0 1.0 \n",
- " \n",
- " RdBu_11 0.0 1.0 \n",
- " \n",
- " Accent_06 0.0 1.0 \n",
- " \n",
- " Set3_03 0.0 1.0 \n",
- " \n",
- " Set3_05 0.0 1.0 \n",
- " \n",
- " Set3_12 0.0 1.0 \n",
- " \n",
- " Set3_10 0.0 1.0 \n",
- " \n",
- " Set3_04 0.0 1.0 \n",
- " \n",
- " RdGy_11 0.0 1.0 \n",
- " \n",
- " RdGy_10 0.0 1.0 \n",
- " \n",
- " Set1_03 0.0 1.0 \n",
- " \n",
- " Set1_09 0.0 1.0 \n",
- " \n",
- " Set3_09 0.0 1.0 \n",
- " \n",
- " BuPu_08 0.0 1.0 \n",
- " \n",
- " BuPu_09 0.0 1.0 \n",
- " \n",
- " RdYlGn_11 0.0 1.0 \n",
- " \n",
- " Blues_03 0.0 1.0 \n",
- " \n",
- " Set2_05 0.0 1.0 \n",
- " \n",
- " BuPu_03 0.0 1.0 \n",
- " \n",
- " BuPu_06 0.0 1.0 \n",
- " \n",
- " BuPu_07 0.0 1.0 \n",
- " \n",
- " BuPu_04 0.0 1.0 \n",
- " \n",
- " BuPu_05 0.0 1.0 \n",
- " \n",
- " Accent_04 0.0 1.0 \n",
- " \n",
- " YlOrRd_05 0.0 1.0 \n",
- " \n",
- " YlOrBr_08 0.0 1.0 \n",
- " \n",
- " Oranges_08 0.0 1.0 \n",
- " \n",
- " Oranges_09 0.0 1.0 \n",
- " \n",
- " Oranges_06 0.0 1.0 \n",
- " \n",
- " Oranges_07 0.0 1.0 \n",
- " \n",
- " Oranges_04 0.0 1.0 \n",
- " \n",
- " YlOrBr_09 0.0 1.0 \n",
- " \n",
- " Oranges_03 0.0 1.0 \n",
- " \n",
- " YlOrBr_06 0.0 1.0 \n",
- " \n",
- " Dark2_06 0.0 1.0 \n",
- " \n",
- " Blues_04 0.0 1.0 \n",
- " \n",
- " YlOrBr_07 0.0 1.0 \n",
- " \n",
- " RdYlGn_05 0.0 1.0 \n",
- " \n",
- " Set3_08 0.0 1.0 \n",
- " \n",
- " YlOrRd_06 0.0 1.0 \n",
- " \n",
- " Dark2_03 0.0 1.0 \n",
- " \n",
- " Accent_05 0.0 1.0 \n",
- " \n",
- " RdYlGn_08 0.0 1.0 \n",
- " \n",
- " RdYlGn_09 0.0 1.0 \n",
- " \n",
- " PuOr_11 0.0 1.0 \n",
- " \n",
- " YlOrRd_07 0.0 1.0 \n",
- " \n",
- " Spectral_11 0.0 1.0 \n",
- " \n",
- " RdGy_08 0.0 1.0 \n",
- " \n",
- " RdGy_09 0.0 1.0 \n",
- " \n",
- " RdGy_06 0.0 1.0 \n",
- " \n",
- " RdGy_07 0.0 1.0 \n",
- " \n",
- " RdGy_04 0.0 1.0 \n",
- " \n",
- " RdGy_05 0.0 1.0 \n",
- " \n",
- " RdYlGn_04 0.0 1.0 \n",
- " \n",
- " PiYG_09 0.0 1.0 \n",
- " \n",
- " RdYlGn_06 0.0 1.0 \n",
- " \n",
- " RdYlGn_07 0.0 1.0 \n",
- " \n",
- " Spectral_04 0.0 1.0 \n",
- " \n",
- " Spectral_05 0.0 1.0 \n",
- " \n",
- " Spectral_06 0.0 1.0 \n",
- " \n",
- " PiYG_08 0.0 1.0 \n",
- " \n",
- " Set2_03 0.0 1.0 \n",
- " \n",
- " Spectral_03 0.0 1.0 \n",
- " \n",
- " Reds_08 0.0 1.0 \n",
- " \n",
- " Set1_04 0.0 1.0 \n",
- " \n",
- " Spectral_08 0.0 1.0 \n",
- " \n",
- " Spectral_09 0.0 1.0 \n",
- " \n",
- " Set2_08 0.0 1.0 \n",
- " \n",
- " Reds_09 0.0 1.0 \n",
- " \n",
- " Greys_07 0.0 1.0 \n",
- " \n",
- " Greys_06 0.0 1.0 \n",
- " \n",
- " Greys_05 0.0 1.0 \n",
- " \n",
- " Greys_04 0.0 1.0 \n",
- " \n",
- " Greys_03 0.0 1.0 \n",
- " \n",
- " PuOr_10 0.0 1.0 \n",
- " \n",
- " Accent_07 0.0 1.0 \n",
- " \n",
- " Reds_06 0.0 1.0 \n",
- " \n",
- " Greys_09 0.0 1.0 \n",
- " \n",
- " Greys_08 0.0 1.0 \n",
- " \n",
- " Reds_07 0.0 1.0 \n",
- " \n",
- " RdYlBu_08 0.0 1.0 \n",
- " \n",
- " RdYlBu_09 0.0 1.0 \n",
- " \n",
- " BrBG_09 0.0 1.0 \n",
- " \n",
- " BrBG_08 0.0 1.0 \n",
- " \n",
- " BrBG_07 0.0 1.0 \n",
- " \n",
- " BrBG_06 0.0 1.0 \n",
- " \n",
- " BrBG_05 0.0 1.0 \n",
- " \n",
- " BrBG_04 0.0 1.0 \n",
- " \n",
- " BrBG_03 0.0 1.0 \n",
- " \n",
- " PiYG_06 0.0 1.0 \n",
- " \n",
- " Reds_03 0.0 1.0 \n",
- " \n",
- " Set3_11 0.0 1.0 \n",
- " \n",
- " Set1_06 0.0 1.0 \n",
- " \n",
- " PuRd_03 0.0 1.0 \n",
- " \n",
- " PiYG_07 0.0 1.0 \n",
- " \n",
- " RdBu_07 0.0 1.0 \n",
- " \n",
- " Pastel1_06 0.0 1.0 \n",
- " \n",
- " Spectral_10 0.0 1.0 \n",
- " \n",
- " PuRd_04 0.0 1.0 \n",
- " \n",
- " OrRd_03 0.0 1.0 \n",
- " \n",
- " PiYG_03 0.0 1.0 \n",
- " \n",
- " Oranges_05 0.0 1.0 \n",
- " \n",
- " OrRd_07 0.0 1.0 \n",
- " \n",
- " OrRd_06 0.0 1.0 \n",
- " \n",
- " OrRd_05 0.0 1.0 \n",
- " \n",
- " OrRd_04 0.0 1.0 \n",
- " \n",
- " Reds_04 0.0 1.0 \n",
- " \n",
- " Reds_05 0.0 1.0 \n",
- " \n",
- " OrRd_09 0.0 1.0 \n",
- " \n",
- " OrRd_08 0.0 1.0 \n",
- " \n",
- " BrBG_10 0.0 1.0 \n",
- " \n",
- " BrBG_11 0.0 1.0 \n",
- " \n",
- " PiYG_05 0.0 1.0 \n",
- " \n",
- " YlOrRd_08 0.0 1.0 \n",
- " \n",
- " GnBu_04 0.0 1.0 \n",
- " \n",
- " GnBu_05 0.0 1.0 \n",
- " \n",
- " GnBu_06 0.0 1.0 \n",
- " \n",
- " GnBu_07 0.0 1.0 \n",
- " \n",
- " Purples_08 0.0 1.0 \n",
- " \n",
- " GnBu_03 0.0 1.0 \n",
- " \n",
- " Purples_06 0.0 1.0 \n",
- " \n",
- " Purples_07 0.0 1.0 \n",
- " \n",
- " Purples_04 0.0 1.0 \n",
- " \n",
- " Purples_05 0.0 1.0 \n",
- " \n",
- " GnBu_08 0.0 1.0 \n",
- " \n",
- " GnBu_09 0.0 1.0 \n",
- " \n",
- " YlOrRd_09 0.0 1.0 \n",
- " \n",
- " Purples_03 0.0 1.0 \n",
- " \n",
- " RdYlBu_04 0.0 1.0 \n",
- " \n",
- " PRGn_09 0.0 1.0 \n",
- " \n",
- " PRGn_08 0.0 1.0 \n",
- " \n",
- " PRGn_07 0.0 1.0 \n",
- " \n",
- " PRGn_06 0.0 1.0 \n",
- " \n",
- " PRGn_05 0.0 1.0 \n",
- " \n",
- " PRGn_04 0.0 1.0 \n",
- " \n",
- " PRGn_03 0.0 1.0 \n",
- " \n",
- " RdYlBu_06 0.0 1.0 \n",
- " \n",
- " RdYlGn_10 0.0 1.0 \n",
- " \n",
- " YlGn_08 0.0 1.0 \n",
- " \n",
- " YlGn_09 0.0 1.0 \n",
- " \n",
- " RdYlBu_07 0.0 1.0 \n",
- " \n",
- " PiYG_10 0.0 1.0 \n",
- " \n",
- " PiYG_11 0.0 1.0 \n",
- " \n",
- " YlGn_03 0.0 1.0 \n",
- " \n",
- " YlGn_04 0.0 1.0 \n",
- " \n",
- " YlGn_05 0.0 1.0 \n",
- " \n",
- " YlGn_06 0.0 1.0 \n",
- " \n",
- " YlGn_07 0.0 1.0 \n",
- " \n",
- " Dark2_05 0.0 1.0 \n",
- " \n",
- " Dark2_04 0.0 1.0 \n",
- " \n",
- " Dark2_07 0.0 1.0 \n",
- " \n",
- " Pastel2_03 0.0 1.0 \n",
- " \n",
- " Pastel2_04 0.0 1.0 \n",
- " \n",
- " Pastel2_05 0.0 1.0 \n",
- " \n",
- " Pastel2_06 0.0 1.0 \n",
- " \n",
- " Pastel2_07 0.0 1.0 \n",
- " \n",
- " Pastel2_08 0.0 1.0 \n",
- " \n",
- " RdYlBu_03 0.0 1.0 \n",
- " \n",
- " Dark2_08 0.0 1.0 \n",
- " \n",
- " RdYlGn_03 0.0 1.0 \n",
- " \n",
- " PRGn_11 0.0 1.0 \n",
- " \n",
- " Greens_08 0.0 1.0 \n",
- " \n",
- " Greens_09 0.0 1.0 \n",
- " \n",
- " Greens_06 0.0 1.0 \n",
- " \n",
- " Greens_07 0.0 1.0 \n",
- " \n",
- " Greens_04 0.0 1.0 \n",
- " \n",
- " Greens_05 0.0 1.0 \n",
- " \n",
- " PRGn_10 0.0 1.0 \n",
- " \n",
- " Greens_03 0.0 1.0 \n",
- "
\n",
- " "
- ],
- "text/plain": [
- ""
- ]
- },
- "execution_count": 17,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "cm.linear"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "## Draw a `ColorMap` on a map\n",
- "\n",
- "By the way, a ColorMap is also a Folium `Element` that you can draw on a map."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 18,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "Make this Notebook Trusted to load map: File -> Trust Notebook
"
- ],
- "text/plain": [
- ""
- ]
- },
- "execution_count": 18,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "m = folium.Map(tiles=\"cartodbpositron\")\n",
- "\n",
- "colormap = cm.linear.Set1_09.scale(0, 35).to_step(10)\n",
- "colormap.caption = \"A colormap caption\"\n",
- "m.add_child(colormap)\n",
- "\n",
- "m"
- ]
+ "metadata": {
+ "collapsed": false
+ }
}
],
"metadata": {
diff --git a/examples/ContinuousWorld.ipynb b/examples/ContinuousWorld.ipynb
index d2554d85b..3da78e8ac 100644
--- a/examples/ContinuousWorld.ipynb
+++ b/examples/ContinuousWorld.ipynb
@@ -2,116 +2,13 @@
"cells": [
{
"cell_type": "markdown",
- "metadata": {},
"source": [
- "## Defaults"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 1,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "Make this Notebook Trusted to load map: File -> Trust Notebook
"
- ],
- "text/plain": [
- ""
- ]
- },
- "execution_count": 1,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "import folium\n",
- "\n",
- "\n",
- "m = folium.Map(world_copy_jump=False, no_wrap=False)\n",
- "\n",
- "folium.Marker(\n",
- " location=[0, 0], popup=\"I will disappear when moved outside the wrapped map domain.\"\n",
- ").add_to(m)\n",
- "\n",
- "m"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "## World copy jump"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 2,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "Make this Notebook Trusted to load map: File -> Trust Notebook
"
- ],
- "text/plain": [
- ""
- ]
- },
- "execution_count": 2,
- "metadata": {},
- "output_type": "execute_result"
- }
+ "We've updated our documentation. You can find the new version of this notebook here:\n",
+ "https://python-visualization.github.io/folium/latest/advanced_guide/world_copy.html"
],
- "source": [
- "m = folium.Map(world_copy_jump=True, no_wrap=False)\n",
- "\n",
- "folium.Marker(\n",
- " location=[0, 0],\n",
- " popup=\"I will magically reappear when moved outside the wrapped map domain.\",\n",
- ").add_to(m)\n",
- "\n",
- "m"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "## No wrap"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 3,
- "metadata": {},
- "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(\n",
- " world_copy_jump=False,\n",
- " no_wrap=True,\n",
- ")\n",
- "\n",
- "folium.Marker(location=[0, 0], popup=\"The map domain here is not wrapped!\").add_to(m)\n",
- "\n",
- "m"
- ]
+ "metadata": {
+ "collapsed": false
+ }
}
],
"metadata": {
diff --git a/examples/ControlScale.ipynb b/examples/ControlScale.ipynb
index 3df3d26ba..c161a3098 100644
--- a/examples/ControlScale.ipynb
+++ b/examples/ControlScale.ipynb
@@ -1,41 +1,14 @@
{
"cells": [
{
- "cell_type": "code",
- "execution_count": 1,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "Make this Notebook Trusted to load map: File -> Trust Notebook
"
- ],
- "text/plain": [
- ""
- ]
- },
- "execution_count": 1,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "cell_type": "markdown",
"source": [
- "import folium\n",
- "\n",
- "\n",
- "lon, lat = -38.625, -12.875\n",
- "\n",
- "zoom_start = 8\n",
- "\n",
- "m = folium.Map(\n",
- " location=[lat, lon],\n",
- " tiles=\"OpenStreetMap\",\n",
- " zoom_start=zoom_start,\n",
- " control_scale=True,\n",
- ")\n",
- "\n",
- "m"
- ]
+ "We've updated our documentation. You can find the new version of this notebook here:\n",
+ "https://python-visualization.github.io/folium/latest/user_guide/map.html#Scale"
+ ],
+ "metadata": {
+ "collapsed": false
+ }
}
],
"metadata": {
diff --git a/examples/CustomIcon.ipynb b/examples/CustomIcon.ipynb
index 0cd8364c7..636eec657 100644
--- a/examples/CustomIcon.ipynb
+++ b/examples/CustomIcon.ipynb
@@ -1,53 +1,15 @@
{
"cells": [
{
- "cell_type": "code",
- "execution_count": 1,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "Make this Notebook Trusted to load map: File -> Trust Notebook
"
- ],
- "text/plain": [
- ""
- ]
- },
- "execution_count": 1,
- "metadata": {},
- "output_type": "execute_result"
+ "cell_type": "markdown",
+ "metadata": {
+ "pycharm": {
+ "name": "#%% md\n"
}
- ],
+ },
"source": [
- "import folium\n",
- "from folium.features import CustomIcon\n",
- "\n",
- "\n",
- "m = folium.Map(location=[45.372, -121.6972], zoom_start=12, tiles=\"Stamen Terrain\")\n",
- "\n",
- "url = \"http://leafletjs.com/examples/custom-icons/{}\".format\n",
- "icon_image = url(\"leaf-red.png\")\n",
- "shadow_image = url(\"leaf-shadow.png\")\n",
- "\n",
- "icon = CustomIcon(\n",
- " icon_image,\n",
- " icon_size=(38, 95),\n",
- " icon_anchor=(22, 94),\n",
- " shadow_image=shadow_image,\n",
- " shadow_size=(50, 64),\n",
- " shadow_anchor=(4, 62),\n",
- " popup_anchor=(-3, -76),\n",
- ")\n",
- "\n",
- "marker = folium.Marker(\n",
- " location=[45.3288, -121.6625], icon=icon, popup=\"Mt. Hood Meadows\"\n",
- ")\n",
- "\n",
- "\n",
- "m.add_child(marker)\n",
- "\n",
- "m"
+ "We've updated our documentation. You can find the new version of this notebook here:\n",
+ "https://python-visualization.github.io/folium/latest/user_guide/ui_elements/icons.html#Custom-icon"
]
}
],
diff --git a/examples/CustomPanes.ipynb b/examples/CustomPanes.ipynb
index a547b9145..c44289705 100644
--- a/examples/CustomPanes.ipynb
+++ b/examples/CustomPanes.ipynb
@@ -2,175 +2,13 @@
"cells": [
{
"cell_type": "markdown",
- "metadata": {},
"source": [
- "Load GeoJSON as in [GeoJSON_and_choropleth.ipynb](https://github.com/python-visualization/folium/blob/main/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/main/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"
- }
+ "We've updated our documentation. You can find the new version of this notebook here:\n",
+ "https://python-visualization.github.io/folium/latest/advanced_guide/custom_panes.html"
],
- "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/."
- ]
+ "collapsed": false
+ }
}
],
"metadata": {
diff --git a/examples/FeatureGroup.ipynb b/examples/FeatureGroup.ipynb
index 0179d335d..543ab5c3f 100644
--- a/examples/FeatureGroup.ipynb
+++ b/examples/FeatureGroup.ipynb
@@ -1,40 +1,14 @@
{
"cells": [
{
- "cell_type": "code",
- "execution_count": 1,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "Make this Notebook Trusted to load map: File -> Trust Notebook
"
- ],
- "text/plain": [
- ""
- ]
- },
- "execution_count": 1,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "cell_type": "markdown",
"source": [
- "from folium import FeatureGroup, LayerControl, Map, Marker\n",
- "\n",
- "\n",
- "m = Map(location=[45.372, -121.6972], zoom_start=12, tiles=\"Stamen Terrain\")\n",
- "\n",
- "feature_group = FeatureGroup(name=\"Some icons\")\n",
- "Marker(location=[45.3288, -121.6625], popup=\"Mt. Hood Meadows\").add_to(feature_group)\n",
- "\n",
- "Marker(location=[45.3311, -121.7113], popup=\"Timberline Lodge\").add_to(feature_group)\n",
- "\n",
- "feature_group.add_to(m)\n",
- "LayerControl().add_to(m)\n",
- "\n",
- "m"
- ]
+ "We've updated our documentation. You can find the new version of this notebook here:\n",
+ "https://python-visualization.github.io/folium/latest/getting_started.html#Grouping-and-controlling"
+ ],
+ "metadata": {
+ "collapsed": false
+ }
}
],
"metadata": {
diff --git a/examples/Features.ipynb b/examples/Features.ipynb
index 974cf5565..d55d0dac7 100644
--- a/examples/Features.ipynb
+++ b/examples/Features.ipynb
@@ -2,1554 +2,14 @@
"cells": [
{
"cell_type": "markdown",
- "metadata": {},
- "source": [
- "## ColorLine"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 1,
- "metadata": {},
- "outputs": [],
- "source": [
- "import numpy as np\n",
- "\n",
- "x = np.linspace(0, 2 * np.pi, 300)\n",
- "\n",
- "lats = 20 * np.cos(x)\n",
- "lons = 20 * np.sin(x)\n",
- "colors = np.sin(5 * x)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 2,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "Make this Notebook Trusted to load map: File -> Trust Notebook
"
- ],
- "text/plain": [
- ""
- ]
- },
- "execution_count": 2,
- "metadata": {},
- "output_type": "execute_result"
+ "metadata": {
+ "pycharm": {
+ "name": "#%% md\n"
}
- ],
- "source": [
- "import folium\n",
- "from folium import features\n",
- "\n",
- "\n",
- "m = folium.Map([0, 0], zoom_start=3)\n",
- "\n",
- "color_line = features.ColorLine(\n",
- " positions=list(zip(lats, lons)),\n",
- " colors=colors,\n",
- " colormap=[\"y\", \"orange\", \"r\"],\n",
- " weight=10,\n",
- ")\n",
- "\n",
- "color_line.add_to(m)\n",
- "\n",
- "m"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### Marker, Icon, Popup"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 3,
- "metadata": {},
- "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([0, 0], zoom_start=1)\n",
- "mk = features.Marker([0, 0])\n",
- "pp = folium.Popup(\"hello\")\n",
- "ic = features.Icon(color=\"red\")\n",
- "\n",
- "mk.add_child(ic)\n",
- "mk.add_child(pp)\n",
- "m.add_child(mk)\n",
- "\n",
- "m"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### Vega popup"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 4,
- "metadata": {},
- "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": [
- "import json\n",
- "\n",
- "import vincent\n",
- "\n",
- "N = 100\n",
- "\n",
- "multi_iter2 = {\n",
- " \"x\": np.random.uniform(size=(N,)),\n",
- " \"y\": np.random.uniform(size=(N,)),\n",
- "}\n",
- "\n",
- "scatter = vincent.Scatter(multi_iter2, iter_idx=\"x\", height=100, width=200)\n",
- "data = json.loads(scatter.to_json())\n",
- "\n",
- "m = folium.Map([0, 0], zoom_start=1)\n",
- "mk = features.Marker([0, 0])\n",
- "p = folium.Popup(\"Hello\")\n",
- "v = features.Vega(data, width=\"100%\", height=\"100%\")\n",
- "\n",
- "mk.add_child(p)\n",
- "p.add_child(v)\n",
- "m.add_child(mk)\n",
- "\n",
- "m"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### Vega-Lite popup"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 5,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "Make this Notebook Trusted to load map: File -> Trust Notebook
"
- ],
- "text/plain": [
- ""
- ]
- },
- "execution_count": 5,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "from altair import Chart\n",
- "\n",
- "import vega_datasets\n",
- "\n",
- "# load built-in dataset as a pandas DataFrame\n",
- "cars = vega_datasets.data.cars()\n",
- "\n",
- "scatter = (\n",
- " Chart(cars)\n",
- " .mark_circle()\n",
- " .encode(\n",
- " x=\"Horsepower\",\n",
- " y=\"Miles_per_Gallon\",\n",
- " color=\"Origin\",\n",
- " )\n",
- ")\n",
- "\n",
- "vega = folium.features.VegaLite(\n",
- " scatter,\n",
- " width=\"100%\",\n",
- " height=\"100%\",\n",
- ")\n",
- "\n",
- "m = folium.Map(location=[-27.5717, -48.6256])\n",
- "\n",
- "marker = folium.features.Marker([-27.57, -48.62])\n",
- "\n",
- "popup = folium.Popup()\n",
- "\n",
- "vega.add_to(popup)\n",
- "popup.add_to(marker)\n",
- "\n",
- "marker.add_to(m)\n",
- "\n",
- "m"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### Vega div and a Map\n"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 6,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "Make this Notebook Trusted to load map: File -> Trust Notebook
"
- ],
- "text/plain": [
- ""
- ]
- },
- "execution_count": 6,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "import branca\n",
- "\n",
- "N = 100\n",
- "\n",
- "multi_iter2 = {\n",
- " \"x\": np.random.uniform(size=(N,)),\n",
- " \"y\": np.random.uniform(size=(N,)),\n",
- "}\n",
- "\n",
- "scatter = vincent.Scatter(multi_iter2, iter_idx=\"x\", height=250, width=420)\n",
- "data = json.loads(scatter.to_json())\n",
- "\n",
- "f = branca.element.Figure()\n",
- "\n",
- "# Create two maps.\n",
- "m = folium.Map(\n",
- " location=[0, 0],\n",
- " tiles=\"stamenwatercolor\",\n",
- " zoom_start=1,\n",
- " position=\"absolute\",\n",
- " left=\"0%\",\n",
- " width=\"50%\",\n",
- " height=\"50%\",\n",
- ")\n",
- "\n",
- "m2 = folium.Map(\n",
- " location=[46, 3],\n",
- " tiles=\"OpenStreetMap\",\n",
- " zoom_start=4,\n",
- " position=\"absolute\",\n",
- " left=\"50%\",\n",
- " width=\"50%\",\n",
- " height=\"50%\",\n",
- " top=\"50%\",\n",
- ")\n",
- "\n",
- "# Create two Vega.\n",
- "v = features.Vega(data, position=\"absolute\", left=\"50%\", width=\"50%\", height=\"50%\")\n",
- "\n",
- "v2 = features.Vega(\n",
- " data, position=\"absolute\", left=\"0%\", width=\"50%\", height=\"50%\", top=\"50%\"\n",
- ")\n",
- "\n",
- "f.add_child(m)\n",
- "f.add_child(m2)\n",
- "f.add_child(v)\n",
- "f.add_child(v2)\n",
- "\n",
- "f"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### Vega-Lite div and a Map"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 7,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "Make this Notebook Trusted to load map: File -> Trust Notebook
"
- ],
- "text/plain": [
- ""
- ]
- },
- "execution_count": 7,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "import pandas as pd\n",
- "\n",
- "N = 100\n",
- "\n",
- "multi_iter2 = pd.DataFrame(\n",
- " {\n",
- " \"x\": np.random.uniform(size=(N,)),\n",
- " \"y\": np.random.uniform(size=(N,)),\n",
- " }\n",
- ")\n",
- "\n",
- "scatter = Chart(multi_iter2).mark_circle().encode(x=\"x\", y=\"y\")\n",
- "scatter.width = 420\n",
- "scatter.height = 250\n",
- "data = json.loads(scatter.to_json())\n",
- "\n",
- "f = branca.element.Figure()\n",
- "\n",
- "# Create two maps.\n",
- "m = folium.Map(\n",
- " location=[0, 0],\n",
- " tiles=\"stamenwatercolor\",\n",
- " zoom_start=1,\n",
- " position=\"absolute\",\n",
- " left=\"0%\",\n",
- " width=\"50%\",\n",
- " height=\"50%\",\n",
- ")\n",
- "\n",
- "m2 = folium.Map(\n",
- " location=[46, 3],\n",
- " tiles=\"OpenStreetMap\",\n",
- " zoom_start=4,\n",
- " position=\"absolute\",\n",
- " left=\"50%\",\n",
- " width=\"50%\",\n",
- " height=\"50%\",\n",
- " top=\"50%\",\n",
- ")\n",
- "\n",
- "\n",
- "# Create two Vega.\n",
- "v = features.VegaLite(data, position=\"absolute\", left=\"50%\", width=\"50%\", height=\"50%\")\n",
- "\n",
- "v2 = features.VegaLite(\n",
- " data, position=\"absolute\", left=\"0%\", width=\"50%\", height=\"50%\", top=\"50%\"\n",
- ")\n",
- "\n",
- "f.add_child(m)\n",
- "f.add_child(m2)\n",
- "f.add_child(v)\n",
- "f.add_child(v2)\n",
- "\n",
- "f"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### GeoJson"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 8,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "Make this Notebook Trusted to load map: File -> Trust Notebook
"
- ],
- "text/plain": [
- ""
- ]
- },
- "execution_count": 8,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "N = 1000\n",
- "\n",
- "lons = +5 - np.random.normal(size=N)\n",
- "lats = 48 - np.random.normal(size=N)\n",
- "\n",
- "data = {\n",
- " \"type\": \"FeatureCollection\",\n",
- " \"features\": [\n",
- " {\n",
- " \"type\": \"Feature\",\n",
- " \"geometry\": {\n",
- " \"type\": \"MultiPoint\",\n",
- " \"coordinates\": [[lon, lat] for (lat, lon) in zip(lats, lons)],\n",
- " },\n",
- " \"properties\": {\"prop0\": \"value0\"},\n",
- " },\n",
- " ],\n",
- "}\n",
- "\n",
- "m = folium.Map([48, 5], zoom_start=6)\n",
- "m.add_child(features.GeoJson(data))\n",
- "\n",
- "m"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### Div"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 9,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "Make this Notebook Trusted to load map: File -> Trust Notebook
"
- ],
- "text/plain": [
- ""
- ]
- },
- "execution_count": 9,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "N = 100\n",
- "\n",
- "multi_iter2 = {\n",
- " \"x\": np.random.uniform(size=(N,)),\n",
- " \"y\": np.random.uniform(size=(N,)),\n",
- "}\n",
- "\n",
- "scatter = vincent.Scatter(multi_iter2, iter_idx=\"x\", height=250, width=420)\n",
- "data = json.loads(scatter.to_json())\n",
- "\n",
- "f = branca.element.Figure()\n",
- "\n",
- "d1 = f.add_subplot(1, 2, 1)\n",
- "d2 = f.add_subplot(1, 2, 2)\n",
- "\n",
- "d1.add_child(folium.Map([0, 0], tiles=\"stamenwatercolor\", zoom_start=1))\n",
- "d2.add_child(folium.Map([46, 3], tiles=\"OpenStreetMap\", zoom_start=5))\n",
- "\n",
- "f"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### LayerControl"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 10,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "Make this Notebook Trusted to load map: File -> Trust Notebook
"
- ],
- "text/plain": [
- ""
- ]
- },
- "execution_count": 10,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ },
"source": [
- "m = folium.Map(tiles=None)\n",
- "\n",
- "folium.raster_layers.TileLayer(\"OpenStreetMap\").add_to(m)\n",
- "folium.raster_layers.TileLayer(\"stamentoner\", show=False).add_to(m)\n",
- "\n",
- "folium.LayerControl(collapsed=False).add_to(m)\n",
- "\n",
- "m"
+ "We've updated our documentation. You can find the new version of this notebook here:\n",
+ "https://python-visualization.github.io/folium/latest/user_guide.html"
]
}
],
diff --git a/examples/FitOverlays.ipynb b/examples/FitOverlays.ipynb
index bb52359cd..ab85d1bc4 100644
--- a/examples/FitOverlays.ipynb
+++ b/examples/FitOverlays.ipynb
@@ -3,502 +3,14 @@
{
"cell_type": "markdown",
"id": "14a617e3",
- "metadata": {},
- "source": [
- "# FitOverlays\n",
- "\n",
- "When you add this class to your map, the map will pan and zoom to fit the enabled overlays."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 1,
- "id": "45275ca3",
- "metadata": {},
- "outputs": [],
- "source": [
- "from folium import Map, LayerControl, FeatureGroup, Marker, FitOverlays"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "fda0a32d",
- "metadata": {},
- "source": [
- "In this first map we placed two markers, but they are not in view. You have to pan or zoom out to find them."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 2,
- "id": "1467934c",
- "metadata": {},
- "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": [
- "def get_map_with_markers():\n",
- " m = Map((52, 0), tiles='cartodbpositron', zoom_start=8)\n",
- "\n",
- " fg1 = FeatureGroup().add_to(m)\n",
- " Marker((52, 5)).add_to(fg1)\n",
- "\n",
- " fg2 = FeatureGroup(show=False).add_to(m)\n",
- " Marker((52, 5.1)).add_to(fg2)\n",
- "\n",
- " LayerControl(collapsed=False).add_to(m)\n",
- " \n",
- " return m\n",
- "\n",
- "get_map_with_markers()"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "ea497a79",
- "metadata": {},
- "source": [
- "Now we add the `FitOverlays` class, which automatically pans and zooms to show the enabled overlays. We show only the first marker by default, if we enable the second marker, the view changes to include it."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 3,
- "id": "fc47cce2",
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "Make this Notebook Trusted to load map: File -> Trust Notebook
"
- ],
- "text/plain": [
- ""
- ]
- },
- "execution_count": 3,
- "metadata": {},
- "output_type": "execute_result"
+ "metadata": {
+ "pycharm": {
+ "name": "#%% md\n"
}
- ],
- "source": [
- "m = get_map_with_markers()\n",
- "\n",
- "FitOverlays().add_to(m)\n",
- "\n",
- "m"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "099d40d3",
- "metadata": {},
- "source": [
- "`FitOverlays` has a couple options:\n",
- "- `padding` adds pixels around the bounds.\n",
- "- `max_zoom` can be used to prevent zooming in too far.\n",
- "- `fly` enables a smoother, longer animation, so you can see how the view changes.\n",
- "- `fit_on_map_load` can be used to disable the fitting that happens when the map loads.\n",
- "\n",
- "Note that `padding` and `max_zoom` can achieve the same effect."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 4,
- "id": "11910053",
- "metadata": {},
- "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 = get_map_with_markers()\n",
- "\n",
- "FitOverlays(\n",
- " padding=0,\n",
- " max_zoom=10,\n",
- " fly=True,\n",
- " fit_on_map_load=False,\n",
- ").add_to(m)\n",
- "\n",
- "m"
+ "We've updated our documentation. You can find the new version of this notebook here:\n",
+ "https://python-visualization.github.io/folium/latest/user_guide/features/fit_overlays.html"
]
}
],
diff --git a/examples/FloatImage.ipynb b/examples/FloatImage.ipynb
index 40d4a6ddc..7bd65133b 100644
--- a/examples/FloatImage.ipynb
+++ b/examples/FloatImage.ipynb
@@ -1,40 +1,14 @@
{
"cells": [
{
- "cell_type": "code",
- "execution_count": 1,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "Make this Notebook Trusted to load map: File -> Trust Notebook
"
- ],
- "text/plain": [
- ""
- ]
- },
- "execution_count": 1,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "cell_type": "markdown",
"source": [
- "import folium\n",
- "from folium.plugins import FloatImage\n",
- "\n",
- "\n",
- "url = (\n",
- " \"https://raw.githubusercontent.com/ocefpaf/secoora_assets_map/\"\n",
- " \"a250729bbcf2ddd12f46912d36c33f7539131bec/secoora_icons/rose.png\"\n",
- ")\n",
- "\n",
- "m = folium.Map([-13, -38.15], zoom_start=10)\n",
- "\n",
- "FloatImage(url, bottom=40, left=65).add_to(m)\n",
- "\n",
- "m"
- ]
+ "We've updated our documentation. You can find the new version of this notebook here:\n",
+ "https://python-visualization.github.io/folium/latest/user_guide/plugins/float_image.html"
+ ],
+ "metadata": {
+ "collapsed": false
+ }
}
],
"metadata": {
diff --git a/examples/GeoJSONMarker.ipynb b/examples/GeoJSONMarker.ipynb
index ca9637f1c..d5818ae19 100644
--- a/examples/GeoJSONMarker.ipynb
+++ b/examples/GeoJSONMarker.ipynb
@@ -2,350 +2,14 @@
"cells": [
{
"cell_type": "markdown",
- "metadata": {},
- "source": [
- "# Using GeoJSON Point Features with Markers"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 22,
- "metadata": {},
- "outputs": [],
- "source": [
- "import os\n",
- "import folium\n",
- "import geopandas as gpd"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 23,
- "metadata": {},
- "outputs": [],
- "source": [
- "rootpath = os.path.abspath(os.getcwd())"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 24,
- "metadata": {},
- "outputs": [],
- "source": [
- "gdf = gpd.read_file(os.path.join(rootpath, \"data\", \"subwaystations.geojson\"))"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 25,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " name \n",
- " url \n",
- " line \n",
- " objectid \n",
- " notes \n",
- " geometry \n",
- " \n",
- " \n",
- " \n",
- " \n",
- " 0 \n",
- " Astor Pl \n",
- " http://web.mta.info/nyct/service/ \n",
- " 4-6-6 Express \n",
- " 1 \n",
- " 4 nights, 6-all times, 6 Express-weekdays AM s... \n",
- " POINT (-73.99107 40.73005) \n",
- " \n",
- " \n",
- " 1 \n",
- " Canal St \n",
- " http://web.mta.info/nyct/service/ \n",
- " 4-6-6 Express \n",
- " 2 \n",
- " 4 nights, 6-all times, 6 Express-weekdays AM s... \n",
- " POINT (-74.00019 40.71880) \n",
- " \n",
- " \n",
- " 2 \n",
- " 50th St \n",
- " http://web.mta.info/nyct/service/ \n",
- " 1-2 \n",
- " 3 \n",
- " 1-all times, 2-nights \n",
- " POINT (-73.98385 40.76173) \n",
- " \n",
- " \n",
- " 3 \n",
- " Bergen St \n",
- " http://web.mta.info/nyct/service/ \n",
- " 2-3-4 \n",
- " 4 \n",
- " 4-nights, 3-all other times, 2-all times \n",
- " POINT (-73.97500 40.68086) \n",
- " \n",
- " \n",
- " 4 \n",
- " Pennsylvania Ave \n",
- " http://web.mta.info/nyct/service/ \n",
- " 3-4 \n",
- " 5 \n",
- " 4-nights, 3-all other times \n",
- " POINT (-73.89489 40.66471) \n",
- " \n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- " name url line \\\n",
- "0 Astor Pl http://web.mta.info/nyct/service/ 4-6-6 Express \n",
- "1 Canal St http://web.mta.info/nyct/service/ 4-6-6 Express \n",
- "2 50th St http://web.mta.info/nyct/service/ 1-2 \n",
- "3 Bergen St http://web.mta.info/nyct/service/ 2-3-4 \n",
- "4 Pennsylvania Ave http://web.mta.info/nyct/service/ 3-4 \n",
- "\n",
- " objectid notes \\\n",
- "0 1 4 nights, 6-all times, 6 Express-weekdays AM s... \n",
- "1 2 4 nights, 6-all times, 6 Express-weekdays AM s... \n",
- "2 3 1-all times, 2-nights \n",
- "3 4 4-nights, 3-all other times, 2-all times \n",
- "4 5 4-nights, 3-all other times \n",
- "\n",
- " geometry \n",
- "0 POINT (-73.99107 40.73005) \n",
- "1 POINT (-74.00019 40.71880) \n",
- "2 POINT (-73.98385 40.76173) \n",
- "3 POINT (-73.97500 40.68086) \n",
- "4 POINT (-73.89489 40.66471) "
- ]
- },
- "execution_count": 25,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "gdf.head()"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 26,
- "metadata": {},
- "outputs": [],
- "source": [
- "gdf['href'] = '' + gdf.url + \" \"\n",
- "gdf['service_level'] = gdf.notes.str.split(', ').apply(lambda x: len([v for v in x if \"all\" in v]))\n",
- "gdf['lines_served'] = gdf.line.str.split('-').apply(lambda x: len(x))"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 27,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "[1, 2, 3, 0]"
- ]
- },
- "execution_count": 27,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "service_levels = gdf.service_level.unique().tolist()\n",
- "service_levels"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 28,
- "metadata": {},
- "outputs": [],
- "source": [
- "colors = [\"orange\", \"yellow\", \"green\", \"blue\"]"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "# Use a Circle as a Marker"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 32,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "Make this Notebook Trusted to load map: File -> Trust Notebook
"
- ],
- "text/plain": [
- ""
- ]
- },
- "execution_count": 32,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "m = folium.Map(location=[40.75, -73.95], zoom_start=13)\n",
- "\n",
- "folium.GeoJson(\n",
- " gdf,\n",
- " name=\"Subway Stations\",\n",
- " marker=folium.Circle(radius=4, fill_color=\"orange\", fill_opacity=0.4, color=\"black\", weight=1),\n",
- " tooltip=folium.GeoJsonTooltip(fields=[\"name\", \"line\", \"notes\"]),\n",
- " popup=folium.GeoJsonPopup(fields=[\"name\", \"line\", \"href\", \"notes\"]),\n",
- " style_function=lambda x: {\n",
- " \"fillColor\": colors[x['properties']['service_level']],\n",
- " \"radius\": (x['properties']['lines_served'])*30,\n",
- " },\n",
- " highlight_function=lambda x: {\"fillOpacity\": 0.8},\n",
- " zoom_on_click=True,\n",
- ").add_to(m)\n",
- "\n",
- "m"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "## Or use a DivIcon"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 30,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "Make this Notebook Trusted to load map: File -> Trust Notebook
"
- ],
- "text/plain": [
- ""
- ]
- },
- "execution_count": 30,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "m = folium.Map(location=[40.75, -73.95], zoom_start=13)\n",
- "\n",
- "\n",
- "def style_function(feature):\n",
- " props = feature.get('properties')\n",
- " markup = f\"\"\"\n",
- " \n",
- " \n",
- "
\n",
- "
\n",
- " {props.get('name')}\n",
- "
\n",
- " \n",
- " \"\"\"\n",
- " return {\"html\": markup}\n",
- "\n",
- "\n",
- "folium.GeoJson(\n",
- " gdf,\n",
- " name=\"Subway Stations\",\n",
- " marker=folium.Marker(icon=folium.DivIcon()),\n",
- " tooltip=folium.GeoJsonTooltip(fields=[\"name\", \"line\", \"notes\"]),\n",
- " popup=folium.GeoJsonPopup(fields=[\"name\", \"line\", \"href\", \"notes\"]),\n",
- " style_function=style_function,\n",
- " zoom_on_click=True,\n",
- ").add_to(m)\n",
- "\n",
- "m"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "## Use a Marker"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 36,
"metadata": {
- "scrolled": true
- },
- "outputs": [
- {
- "data": {
- "text/html": [
- "Make this Notebook Trusted to load map: File -> Trust Notebook
"
- ],
- "text/plain": [
- ""
- ]
- },
- "execution_count": 36,
- "metadata": {},
- "output_type": "execute_result"
+ "pycharm": {
+ "name": "#%% md\n"
}
- ],
+ },
"source": [
- "m = folium.Map(location=[40.75, -73.95], zoom_start=13)\n",
- "\n",
- "marker_colors = [\"red\", \"orange\", \"green\", \"blue\"]\n",
- "\n",
- "folium.GeoJson(\n",
- " gdf,\n",
- " name=\"Subway Stations\",\n",
- " zoom_on_click=True,\n",
- " marker=folium.Marker(icon=folium.Icon(icon='star')),\n",
- " tooltip=folium.GeoJsonTooltip(fields=[\"name\", \"line\", \"notes\"]),\n",
- " popup=folium.GeoJsonPopup(fields=[\"name\", \"line\", \"href\", \"notes\"]),\n",
- " style_function=lambda x: {\n",
- " 'markerColor': marker_colors[x['properties']['service_level']],\n",
- " },\n",
- ").add_to(m)\n",
- "\n",
- "m"
+ "We've updated our documentation. You can find the new version of this notebook here:\n",
+ "https://python-visualization.github.io/folium/latest/user_guide/geojson/geojson_marker.html"
]
}
],
diff --git a/examples/GeoJSONWithoutTitles.ipynb b/examples/GeoJSONWithoutTitles.ipynb
index b4a52510a..815e11034 100644
--- a/examples/GeoJSONWithoutTitles.ipynb
+++ b/examples/GeoJSONWithoutTitles.ipynb
@@ -1,147 +1,15 @@
{
"cells": [
{
- "cell_type": "code",
- "execution_count": 1,
- "metadata": {},
- "outputs": [],
- "source": [
- "import os\n",
- "import json\n",
- "\n",
- "\n",
- "us_states = os.path.join(\"data\", \"us-states.json\")\n",
- "\n",
- "with open(us_states) as f:\n",
- " states = json.load(f)\n",
- "\n",
- "kw = {\"location\": [48, -102], \"zoom_start\": 3}"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 2,
- "metadata": {},
- "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": [
- "import folium\n",
- "from folium import GeoJson\n",
- "\n",
- "\n",
- "m = folium.Map(tiles=None, **kw)\n",
- "\n",
- "GeoJson(states).add_to(m)\n",
- "\n",
- "m"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 3,
- "metadata": {},
- "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": [
- "import branca\n",
- "\n",
- "# Create a white image of 4 pixels, and embed it in a url.\n",
- "white_tile = branca.utilities.image_to_url([[1, 1], [1, 1]])\n",
- "\n",
- "# Create a map using this url for each tile.\n",
- "m = folium.Map(tiles=white_tile, attr=\"white tile\", **kw)\n",
- "\n",
- "GeoJson(states).add_to(m)\n",
- "\n",
- "m"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 4,
- "metadata": {},
- "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": [
- "images = [[(-1) ** ((i + j) // 30) for i in range(300)] for j in range(300)]\n",
- "\n",
- "tiles = branca.utilities.image_to_url(images)\n",
- "\n",
- "m = folium.Map(tiles=tiles, attr=\"Just because we can\", **kw)\n",
- "\n",
- "GeoJson(states).add_to(m)\n",
- "\n",
- "m"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 5,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "Make this Notebook Trusted to load map: File -> Trust Notebook
"
- ],
- "text/plain": [
- ""
- ]
- },
- "execution_count": 5,
- "metadata": {},
- "output_type": "execute_result"
+ "cell_type": "markdown",
+ "metadata": {
+ "pycharm": {
+ "name": "#%% md\n"
}
- ],
+ },
"source": [
- "images = [[(-1) ** ((i // 30 + j // 30)) for i in range(300)] for j in range(300)]\n",
- "\n",
- "tiles = branca.utilities.image_to_url(images)\n",
- "\n",
- "m = folium.Map(tiles=tiles, attr=\"Just because we can\", **kw)\n",
- "\n",
- "GeoJson(states).add_to(m)\n",
- "\n",
- "m"
+ "We've updated our documentation. You can find the new version of this notebook here:\n",
+ "https://python-visualization.github.io/folium/latest/advanced_guide/custom_tiles.html"
]
}
],
diff --git a/examples/GeoJSON_and_choropleth.ipynb b/examples/GeoJSON_and_choropleth.ipynb
index 2ae897ea2..6be025d54 100644
--- a/examples/GeoJSON_and_choropleth.ipynb
+++ b/examples/GeoJSON_and_choropleth.ipynb
@@ -2,882 +2,13 @@
"cells": [
{
"cell_type": "markdown",
- "metadata": {},
"source": [
- "# GeoJSON and choropleth\n",
- "\n",
- "**A few examples of how to do that with `folium`.**\n",
- "\n",
- "\n",
- "## Using `GeoJson`\n",
- "\n",
- "### Loading data\n",
- "\n",
- "Let us load a GeoJSON file representing the US states."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 1,
- "metadata": {},
- "outputs": [],
- "source": [
- "import json\n",
- "\n",
- "import requests\n",
- "\n",
- "url = (\n",
- " \"https://raw.githubusercontent.com/python-visualization/folium/main/examples/data\"\n",
- ")\n",
- "us_states = f\"{url}/us-states.json\"\n",
- "\n",
- "geo_json_data = json.loads(requests.get(us_states).text)"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "It is a classical GeoJSON `FeatureCollection` (see https://en.wikipedia.org/wiki/GeoJSON) of the form :\n",
- "\n",
- " {\n",
- " \"type\": \"FeatureCollection\",\n",
- " \"features\": [\n",
- " {\n",
- " \"properties\": {\"name\": \"Alabama\"},\n",
- " \"id\": \"AL\",\n",
- " \"type\": \"Feature\",\n",
- " \"geometry\": {\n",
- " \"type\": \"Polygon\",\n",
- " \"coordinates\": [[[-87.359296, 35.00118], ...]]\n",
- " }\n",
- " },\n",
- " {\n",
- " \"properties\": {\"name\": \"Alaska\"},\n",
- " \"id\": \"AK\",\n",
- " \"type\": \"Feature\",\n",
- " \"geometry\": {\n",
- " \"type\": \"MultiPolygon\",\n",
- " \"coordinates\": [[[[-131.602021, 55.117982], ... ]]]\n",
- " }\n",
- " },\n",
- " ...\n",
- " ]\n",
- " }\n"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "A first way of drawing it on a map, is simply to use `folium.GeoJson` :"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 2,
- "metadata": {},
- "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": [
- "import folium\n",
- "\n",
- "\n",
- "m = folium.Map([43, -100], zoom_start=4)\n",
- "\n",
- "folium.GeoJson(geo_json_data).add_to(m)\n",
- "\n",
- "m"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "Note that you can avoid loading the file on yourself ; in simply providing a file path."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 3,
- "metadata": {},
- "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)\n",
- "\n",
- "folium.GeoJson(us_states).add_to(m)\n",
- "\n",
- "m"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "You can pass a geopandas object."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 4,
- "metadata": {},
- "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": [
- "import geopandas\n",
- "\n",
- "gdf = geopandas.read_file(us_states)\n",
- "\n",
- "m = folium.Map([43, -100], zoom_start=4)\n",
- "\n",
- "folium.GeoJson(\n",
- " gdf,\n",
- ").add_to(m)\n",
- "\n",
- "m"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### Click on zoom\n",
- "\n",
- "You can enable an option that if you click on a part of the geometry the map will zoom in to that.\n",
- "\n",
- "Try it on the map below:"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 5,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "Make this Notebook Trusted to load map: File -> Trust Notebook
"
- ],
- "text/plain": [
- ""
- ]
- },
- "execution_count": 5,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "m = folium.Map([43, -100], zoom_start=4)\n",
- "\n",
- "folium.GeoJson(geo_json_data, zoom_on_click=True).add_to(m)\n",
- "\n",
- "m"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### Styling\n",
- "\n",
- "Now this is cool and simple, but we may be willing to choose the style of the data.\n",
- "\n",
- "You can provide a function of the form `lambda feature: {}` that sets the style of each feature.\n",
- "\n",
- "For possible options, see:\n",
- "\n",
- "* For `Point` and `MultiPoint`, see http://leafletjs.com/reference.html#marker\n",
- "* For other features, see http://leafletjs.com/reference.html#path-options and http://leafletjs.com/reference.html#polyline-options\n"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 6,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "Make this Notebook Trusted to load map: File -> Trust Notebook
"
- ],
- "text/plain": [
- ""
- ]
- },
- "execution_count": 6,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "m = folium.Map([43, -100], zoom_start=4)\n",
- "\n",
- "folium.GeoJson(\n",
- " geo_json_data,\n",
- " style_function=lambda feature: {\n",
- " \"fillColor\": \"#ffff00\",\n",
- " \"color\": \"black\",\n",
- " \"weight\": 2,\n",
- " \"dashArray\": \"5, 5\",\n",
- " },\n",
- ").add_to(m)\n",
- "\n",
- "m"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "What's cool in providing a function, is that you can specify a style depending on the feature. For example, if you want to visualize in green all states whose name contains the letter 'E', just do:"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 7,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "Make this Notebook Trusted to load map: File -> Trust Notebook
"
- ],
- "text/plain": [
- ""
- ]
- },
- "execution_count": 7,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "m = folium.Map([43, -100], zoom_start=4)\n",
- "\n",
- "folium.GeoJson(\n",
- " geo_json_data,\n",
- " style_function=lambda feature: {\n",
- " \"fillColor\": \"green\"\n",
- " if \"e\" in feature[\"properties\"][\"name\"].lower()\n",
- " else \"#ffff00\",\n",
- " \"color\": \"black\",\n",
- " \"weight\": 2,\n",
- " \"dashArray\": \"5, 5\",\n",
- " },\n",
- ").add_to(m)\n",
- "\n",
- "m"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "Wow, this looks almost like a choropleth. To do one, we just need to compute a color for each state.\n",
- "\n",
- "Let's imagine we want to draw a choropleth of unemployment in the US.\n",
- "\n",
- "First, we may load the data:"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 8,
- "metadata": {
- "scrolled": true
- },
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " State \n",
- " Unemployment \n",
- " \n",
- " \n",
- " \n",
- " \n",
- " 0 \n",
- " AL \n",
- " 7.1 \n",
- " \n",
- " \n",
- " 1 \n",
- " AK \n",
- " 6.8 \n",
- " \n",
- " \n",
- " 2 \n",
- " AZ \n",
- " 8.1 \n",
- " \n",
- " \n",
- " 3 \n",
- " AR \n",
- " 7.2 \n",
- " \n",
- " \n",
- " 4 \n",
- " CA \n",
- " 10.1 \n",
- " \n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- " State Unemployment\n",
- "0 AL 7.1\n",
- "1 AK 6.8\n",
- "2 AZ 8.1\n",
- "3 AR 7.2\n",
- "4 CA 10.1"
- ]
- },
- "execution_count": 8,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "import pandas as pd\n",
- "\n",
- "US_Unemployment_Oct2012 = f\"{url}/US_Unemployment_Oct2012.csv\"\n",
- "unemployment = pd.read_csv(US_Unemployment_Oct2012)\n",
- "\n",
- "unemployment.head(5)"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "Now we need to create a function that maps one value to a RGB color (of the form `#RRGGBB`).\n",
- "For this, we'll use colormap tools from `folium.colormap`."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 9,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "#d8f0a3ff\n"
- ]
- },
- {
- "data": {
- "text/html": [
- "3.2 10.3 "
- ],
- "text/plain": [
- ""
- ]
- },
- "execution_count": 9,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "from branca.colormap import linear\n",
- "\n",
- "colormap = linear.YlGn_09.scale(\n",
- " unemployment.Unemployment.min(), unemployment.Unemployment.max()\n",
- ")\n",
- "\n",
- "print(colormap(5.0))\n",
- "\n",
- "colormap"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "We need also to convert the table into a dictionary, in order to map a feature to it's unemployment value."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 10,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "7.1"
- ]
- },
- "execution_count": 10,
- "metadata": {},
- "output_type": "execute_result"
- }
+ "We've updated our documentation. You can find the new version of this notebook here:\n",
+ "https://python-visualization.github.io/folium/latest/user_guide/geojson.html"
],
- "source": [
- "unemployment_dict = unemployment.set_index(\"State\")[\"Unemployment\"]\n",
- "\n",
- "unemployment_dict[\"AL\"]"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "Now we can do the choropleth."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 11,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "Make this Notebook Trusted to load map: File -> Trust Notebook
"
- ],
- "text/plain": [
- ""
- ]
- },
- "execution_count": 11,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "m = folium.Map([43, -100], zoom_start=4)\n",
- "\n",
- "folium.GeoJson(\n",
- " geo_json_data,\n",
- " name=\"unemployment\",\n",
- " style_function=lambda feature: {\n",
- " \"fillColor\": colormap(unemployment_dict[feature[\"id\"]]),\n",
- " \"color\": \"black\",\n",
- " \"weight\": 1,\n",
- " \"dashArray\": \"5, 5\",\n",
- " \"fillOpacity\": 0.9,\n",
- " },\n",
- ").add_to(m)\n",
- "\n",
- "folium.LayerControl().add_to(m)\n",
- "\n",
- "m"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "Of course, if you can create and/or use a dictionary providing directly the good color. Thus, the finishing seems faster:"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 12,
- "metadata": {},
- "outputs": [],
- "source": [
- "color_dict = {key: colormap(unemployment_dict[key]) for key in unemployment_dict.keys()}"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 13,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- ""
- ]
- },
- "execution_count": 13,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "m = folium.Map([43, -100], zoom_start=4)\n",
- "\n",
- "folium.GeoJson(\n",
- " geo_json_data,\n",
- " style_function=lambda feature: {\n",
- " \"fillColor\": color_dict[feature[\"id\"]],\n",
- " \"color\": \"black\",\n",
- " \"weight\": 1,\n",
- " \"dashArray\": \"5, 5\",\n",
- " \"fillOpacity\": 0.9,\n",
- " },\n",
- ").add_to(m)"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "Note that adding a color legend may be a good idea."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 14,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "Make this Notebook Trusted to load map: File -> Trust Notebook
"
- ],
- "text/plain": [
- ""
- ]
- },
- "execution_count": 14,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "colormap.caption = \"Unemployment color scale\"\n",
- "colormap.add_to(m)\n",
- "\n",
- "m"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "# Using `Choropleth` class\n",
- "\n",
- "Now if you want to get faster, you can use the `Choropleth` class. Have a look at it's docstring, it has several styling options.\n",
- "\n",
- "Just like the `GeoJson` class you can provide it a filename, a dict, or a geopandas object."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 15,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "Make this Notebook Trusted to load map: File -> Trust Notebook
"
- ],
- "text/plain": [
- ""
- ]
- },
- "execution_count": 15,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "m = folium.Map([43, -100], zoom_start=4)\n",
- "\n",
- "folium.Choropleth(\n",
- " geo_data=us_states,\n",
- " fill_opacity=0.3,\n",
- " line_weight=2,\n",
- ").add_to(m)\n",
- "\n",
- "m"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "Then, in playing with keyword arguments, you can get a choropleth in a few lines:"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 16,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "Make this Notebook Trusted to load map: File -> Trust Notebook
"
- ],
- "text/plain": [
- ""
- ]
- },
- "execution_count": 16,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "m = folium.Map([43, -100], zoom_start=4)\n",
- "\n",
- "folium.Choropleth(\n",
- " geo_data=us_states,\n",
- " data=unemployment,\n",
- " columns=[\"State\", \"Unemployment\"],\n",
- " key_on=\"feature.id\",\n",
- ").add_to(m)\n",
- "\n",
- "m"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "You can force the color scale to a given number of bins (or directly list the bins you would like), by providing the `bins` argument."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 17,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "Make this Notebook Trusted to load map: File -> Trust Notebook
"
- ],
- "text/plain": [
- ""
- ]
- },
- "execution_count": 17,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "m = folium.Map([43, -100], zoom_start=4)\n",
- "\n",
- "folium.Choropleth(\n",
- " geo_data=us_states,\n",
- " data=unemployment,\n",
- " columns=[\"State\", \"Unemployment\"],\n",
- " key_on=\"feature.id\",\n",
- " fill_color=\"YlGn\",\n",
- " bins=[3, 4, 9, 11],\n",
- ").add_to(m)\n",
- "\n",
- "m"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "You can also enable the highlight function, to enable highlight functionality when you hover over each area."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 18,
"metadata": {
- "scrolled": false
- },
- "outputs": [
- {
- "data": {
- "text/html": [
- "Make this Notebook Trusted to load map: File -> Trust Notebook
"
- ],
- "text/plain": [
- ""
- ]
- },
- "execution_count": 18,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "state_data = pd.read_csv(US_Unemployment_Oct2012)\n",
- "\n",
- "m = folium.Map(location=[48, -102], zoom_start=3)\n",
- "folium.Choropleth(\n",
- " geo_data=us_states,\n",
- " data=state_data,\n",
- " columns=[\"State\", \"Unemployment\"],\n",
- " key_on=\"feature.id\",\n",
- " fill_color=\"YlGn\",\n",
- " fill_opacity=0.7,\n",
- " line_opacity=0.2,\n",
- " legend_name=\"Unemployment Rate (%)\",\n",
- " highlight=True,\n",
- ").add_to(m)\n",
- "\n",
- "m"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "You can customize the way missing and `nan` values are displayed on your map using the two parameters `nan_fill_color` and `nan_fill_opacity`."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 19,
- "metadata": {
- "scrolled": false
- },
- "outputs": [
- {
- "data": {
- "text/html": [
- "Make this Notebook Trusted to load map: File -> Trust Notebook
"
- ],
- "text/plain": [
- ""
- ]
- },
- "execution_count": 19,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "m = folium.Map([43, -100], zoom_start=4)\n",
- "\n",
- "messed_up_data = unemployment.drop(0)\n",
- "messed_up_data.loc[4, \"Unemployment\"] = float(\"nan\")\n",
- "\n",
- "folium.Choropleth(\n",
- " geo_data=us_states,\n",
- " data=messed_up_data,\n",
- " columns=[\"State\", \"Unemployment\"],\n",
- " nan_fill_color=\"purple\",\n",
- " nan_fill_opacity=0.4,\n",
- " key_on=\"feature.id\",\n",
- " fill_color=\"YlGn\",\n",
- ").add_to(m)\n",
- "\n",
- "m"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "Internally Choropleth uses the `GeoJson` or `TopoJson` class, depending on your settings, and the `StepColormap` class. Both objects are attributes of your `Choropleth` object called `geojson` and `color_scale`. You can make changes to them, but for regular things you won't have to. For example setting a name for in the layer controls or disabling showing the layer on opening the map is possible in `Choropleth` itself."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 20,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "\n",
- "\n"
- ]
- },
- {
- "data": {
- "text/html": [
- "Make this Notebook Trusted to load map: File -> Trust Notebook
"
- ],
- "text/plain": [
- ""
- ]
- },
- "execution_count": 20,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "m = folium.Map([43, -100], zoom_start=4)\n",
- "\n",
- "choropleth = folium.Choropleth(\n",
- " geo_data=us_states,\n",
- " data=state_data,\n",
- " columns=[\"State\", \"Unemployment\"],\n",
- " key_on=\"feature.id\",\n",
- " fill_color=\"YlGn\",\n",
- " name=\"Unenployment\",\n",
- " show=False,\n",
- ").add_to(m)\n",
- "\n",
- "# The underlying GeoJson and StepColormap objects are reachable\n",
- "print(type(choropleth.geojson))\n",
- "print(type(choropleth.color_scale))\n",
- "\n",
- "folium.LayerControl(collapsed=False).add_to(m)\n",
- "\n",
- "m"
- ]
+ "collapsed": false
+ }
}
],
"metadata": {
diff --git a/examples/GeoJsonPopupAndTooltip.ipynb b/examples/GeoJsonPopupAndTooltip.ipynb
index 6b7366e5c..dac3ddee9 100644
--- a/examples/GeoJsonPopupAndTooltip.ipynb
+++ b/examples/GeoJsonPopupAndTooltip.ipynb
@@ -1,956 +1,15 @@
{
"cells": [
{
- "cell_type": "code",
- "execution_count": 18,
- "metadata": {},
- "outputs": [],
- "source": [
- "import pandas as pd\n",
- "\n",
- "\n",
- "income = pd.read_csv(\n",
- " \"https://raw.githubusercontent.com/pri-data/50-states/master/data/income-counties-states-national.csv\",\n",
- " dtype={\"fips\": str},\n",
- ")\n",
- "income[\"income-2015\"] = pd.to_numeric(income[\"income-2015\"], errors=\"coerce\")"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 19,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " fips \n",
- " county \n",
- " state \n",
- " income-2015 \n",
- " income-1989a \n",
- " income-1989b \n",
- " change \n",
- " \n",
- " \n",
- " \n",
- " \n",
- " 0 \n",
- " 00000 \n",
- " US \n",
- " US \n",
- " 55775.0 \n",
- " 28906 \n",
- " 53367.28102 \n",
- " 4.316843 \n",
- " \n",
- " \n",
- " 1 \n",
- " 01000 \n",
- " Alabama \n",
- " AL \n",
- " 44833.0 \n",
- " 22202 \n",
- " 40990.11877 \n",
- " 8.571546 \n",
- " \n",
- " \n",
- " 2 \n",
- " 01001 \n",
- " Autauga County \n",
- " AL \n",
- " 56580.0 \n",
- " 26898 \n",
- " 49660.04030 \n",
- " 12.230399 \n",
- " \n",
- " \n",
- " 3 \n",
- " 01003 \n",
- " Baldwin County \n",
- " AL \n",
- " 52387.0 \n",
- " 24043 \n",
- " 44389.03818 \n",
- " 15.267074 \n",
- " \n",
- " \n",
- " 4 \n",
- " 01005 \n",
- " Barbour County \n",
- " AL \n",
- " 31433.0 \n",
- " 18673 \n",
- " 34474.75398 \n",
- " -9.676945 \n",
- " \n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- " fips county state income-2015 income-1989a income-1989b \n",
- "0 00000 US US 55775.0 28906 53367.28102 \\\n",
- "1 01000 Alabama AL 44833.0 22202 40990.11877 \n",
- "2 01001 Autauga County AL 56580.0 26898 49660.04030 \n",
- "3 01003 Baldwin County AL 52387.0 24043 44389.03818 \n",
- "4 01005 Barbour County AL 31433.0 18673 34474.75398 \n",
- "\n",
- " change \n",
- "0 4.316843 \n",
- "1 8.571546 \n",
- "2 12.230399 \n",
- "3 15.267074 \n",
- "4 -9.676945 "
- ]
- },
- "execution_count": 19,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "income.head()"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 20,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " geometry \n",
- " name \n",
- " \n",
- " \n",
- " \n",
- " \n",
- " 0 \n",
- " POLYGON ((-87.35930 35.00118, -85.60667 34.984... \n",
- " Alabama \n",
- " \n",
- " \n",
- " 1 \n",
- " MULTIPOLYGON (((-131.60202 55.11798, -131.5691... \n",
- " Alaska \n",
- " \n",
- " \n",
- " 2 \n",
- " POLYGON ((-109.04250 37.00026, -109.04798 31.3... \n",
- " Arizona \n",
- " \n",
- " \n",
- " 3 \n",
- " POLYGON ((-94.47384 36.50186, -90.15254 36.496... \n",
- " Arkansas \n",
- " \n",
- " \n",
- " 4 \n",
- " POLYGON ((-123.23326 42.00619, -122.37885 42.0... \n",
- " California \n",
- " \n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- " geometry name\n",
- "0 POLYGON ((-87.35930 35.00118, -85.60667 34.984... Alabama\n",
- "1 MULTIPOLYGON (((-131.60202 55.11798, -131.5691... Alaska\n",
- "2 POLYGON ((-109.04250 37.00026, -109.04798 31.3... Arizona\n",
- "3 POLYGON ((-94.47384 36.50186, -90.15254 36.496... Arkansas\n",
- "4 POLYGON ((-123.23326 42.00619, -122.37885 42.0... California"
- ]
- },
- "execution_count": 20,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "import requests\n",
- "import geopandas\n",
- "\n",
- "\n",
- "response = requests.get(\n",
- " \"https://raw.githubusercontent.com/python-visualization/folium/main/examples/data/us-states.json\"\n",
- ")\n",
- "data = response.json()\n",
- "states = geopandas.GeoDataFrame.from_features(data, crs=\"EPSG:4326\")\n",
- "\n",
- "states.head()"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 21,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " name \n",
- " alpha-2 \n",
- " \n",
- " \n",
- " \n",
- " \n",
- " 0 \n",
- " Alabama \n",
- " AL \n",
- " \n",
- " \n",
- " 1 \n",
- " Alaska \n",
- " AK \n",
- " \n",
- " \n",
- " 2 \n",
- " Arizona \n",
- " AZ \n",
- " \n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- " name alpha-2\n",
- "0 Alabama AL\n",
- "1 Alaska AK\n",
- "2 Arizona AZ"
- ]
- },
- "execution_count": 21,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "response = requests.get(\n",
- " \"https://gist.githubusercontent.com/tvpmb/4734703/raw/\"\n",
- " \"b54d03154c339ed3047c66fefcece4727dfc931a/US%2520State%2520List\"\n",
- ")\n",
- "abbrs = pd.read_json(response.text)\n",
- "\n",
- "abbrs.head(3)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 22,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " geometry \n",
- " name \n",
- " alpha-2 \n",
- " \n",
- " \n",
- " \n",
- " \n",
- " 0 \n",
- " POLYGON ((-87.35930 35.00118, -85.60667 34.984... \n",
- " Alabama \n",
- " AL \n",
- " \n",
- " \n",
- " 1 \n",
- " MULTIPOLYGON (((-131.60202 55.11798, -131.5691... \n",
- " Alaska \n",
- " AK \n",
- " \n",
- " \n",
- " 2 \n",
- " POLYGON ((-109.04250 37.00026, -109.04798 31.3... \n",
- " Arizona \n",
- " AZ \n",
- " \n",
- " \n",
- " 3 \n",
- " POLYGON ((-94.47384 36.50186, -90.15254 36.496... \n",
- " Arkansas \n",
- " AR \n",
- " \n",
- " \n",
- " 4 \n",
- " POLYGON ((-123.23326 42.00619, -120.00186 41.9... \n",
- " California \n",
- " CA \n",
- " \n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- " geometry name alpha-2\n",
- "0 POLYGON ((-87.35930 35.00118, -85.60667 34.984... Alabama AL\n",
- "1 MULTIPOLYGON (((-131.60202 55.11798, -131.5691... Alaska AK\n",
- "2 POLYGON ((-109.04250 37.00026, -109.04798 31.3... Arizona AZ\n",
- "3 POLYGON ((-94.47384 36.50186, -90.15254 36.496... Arkansas AR\n",
- "4 POLYGON ((-123.23326 42.00619, -120.00186 41.9... California CA"
- ]
- },
- "execution_count": 22,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "statesmerge = states.merge(abbrs, how=\"left\", left_on=\"name\", right_on=\"name\")\n",
- "statesmerge[\"geometry\"] = statesmerge.geometry.simplify(0.05)\n",
- "\n",
- "statesmerge.head()"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 23,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "state\n",
- "AK 62561.5\n",
- "AL 38721.5\n",
- "AR 37890.0\n",
- "AZ 43810.0\n",
- "CA 53341.0\n",
- "Name: income-2015, dtype: float64"
- ]
- },
- "execution_count": 23,
- "metadata": {},
- "output_type": "execute_result"
+ "cell_type": "markdown",
+ "metadata": {
+ "pycharm": {
+ "name": "#%% md\n"
}
- ],
- "source": [
- "income.groupby(\"state\")[\"income-2015\"].median().head()"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 24,
- "metadata": {},
- "outputs": [],
- "source": [
- "statesmerge[\"medianincome\"] = statesmerge.merge(\n",
- " income.groupby(\"state\")[\"income-2015\"].median(),\n",
- " how=\"left\",\n",
- " left_on=\"alpha-2\",\n",
- " right_on=\"state\",\n",
- ")[\"income-2015\"]\n",
- "statesmerge[\"change\"] = statesmerge.merge(\n",
- " income.groupby(\"state\")[\"change\"].median(),\n",
- " how=\"left\",\n",
- " left_on=\"alpha-2\",\n",
- " right_on=\"state\",\n",
- ")[\"change\"]"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 25,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " geometry \n",
- " name \n",
- " alpha-2 \n",
- " medianincome \n",
- " change \n",
- " \n",
- " \n",
- " \n",
- " \n",
- " 0 \n",
- " POLYGON ((-87.35930 35.00118, -85.60667 34.984... \n",
- " Alabama \n",
- " AL \n",
- " 38721.5 \n",
- " 2.779114 \n",
- " \n",
- " \n",
- " 1 \n",
- " MULTIPOLYGON (((-131.60202 55.11798, -131.5691... \n",
- " Alaska \n",
- " AK \n",
- " 62561.5 \n",
- " 14.758367 \n",
- " \n",
- " \n",
- " 2 \n",
- " POLYGON ((-109.04250 37.00026, -109.04798 31.3... \n",
- " Arizona \n",
- " AZ \n",
- " 43810.0 \n",
- " NaN \n",
- " \n",
- " \n",
- " 3 \n",
- " POLYGON ((-94.47384 36.50186, -90.15254 36.496... \n",
- " Arkansas \n",
- " AR \n",
- " 37890.0 \n",
- " 10.897394 \n",
- " \n",
- " \n",
- " 4 \n",
- " POLYGON ((-123.23326 42.00619, -120.00186 41.9... \n",
- " California \n",
- " CA \n",
- " 53341.0 \n",
- " 6.716596 \n",
- " \n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- " geometry name alpha-2 \n",
- "0 POLYGON ((-87.35930 35.00118, -85.60667 34.984... Alabama AL \\\n",
- "1 MULTIPOLYGON (((-131.60202 55.11798, -131.5691... Alaska AK \n",
- "2 POLYGON ((-109.04250 37.00026, -109.04798 31.3... Arizona AZ \n",
- "3 POLYGON ((-94.47384 36.50186, -90.15254 36.496... Arkansas AR \n",
- "4 POLYGON ((-123.23326 42.00619, -120.00186 41.9... California CA \n",
- "\n",
- " medianincome change \n",
- "0 38721.5 2.779114 \n",
- "1 62561.5 14.758367 \n",
- "2 43810.0 NaN \n",
- "3 37890.0 10.897394 \n",
- "4 53341.0 6.716596 "
- ]
- },
- "execution_count": 25,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "statesmerge.head()"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 26,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "43969.375"
- ]
- },
- "execution_count": 26,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "statesmerge[\"medianincome\"].quantile(0.25)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 27,
- "metadata": {},
- "outputs": [],
- "source": [
- "import branca\n",
- "\n",
- "\n",
- "colormap = branca.colormap.LinearColormap(\n",
- " vmin=statesmerge[\"change\"].quantile(0.0),\n",
- " vmax=statesmerge[\"change\"].quantile(1),\n",
- " colors=[\"red\", \"orange\", \"lightblue\", \"green\", \"darkgreen\"],\n",
- " caption=\"State Level Median County Household Income (%)\",\n",
- ")"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 28,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "Make this Notebook Trusted to load map: File -> Trust Notebook
"
- ],
- "text/plain": [
- ""
- ]
- },
- "execution_count": 28,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ },
"source": [
- "import folium\n",
- "from folium.features import GeoJsonPopup, GeoJsonTooltip\n",
- "\n",
- "\n",
- "m = folium.Map(location=[35.3, -97.6], zoom_start=4)\n",
- "\n",
- "popup = GeoJsonPopup(\n",
- " fields=[\"name\", \"change\"],\n",
- " aliases=[\"State\", \"% Change\"],\n",
- " localize=True,\n",
- " labels=True,\n",
- " style=\"background-color: yellow;\",\n",
- ")\n",
- "\n",
- "tooltip = GeoJsonTooltip(\n",
- " fields=[\"name\", \"medianincome\", \"change\"],\n",
- " aliases=[\"State:\", \"2015 Median Income(USD):\", \"Median % Change:\"],\n",
- " localize=True,\n",
- " sticky=False,\n",
- " labels=True,\n",
- " style=\"\"\"\n",
- " background-color: #F0EFEF;\n",
- " border: 2px solid black;\n",
- " border-radius: 3px;\n",
- " box-shadow: 3px;\n",
- " \"\"\",\n",
- " max_width=800,\n",
- ")\n",
- "\n",
- "\n",
- "g = folium.GeoJson(\n",
- " statesmerge,\n",
- " style_function=lambda x: {\n",
- " \"fillColor\": colormap(x[\"properties\"][\"change\"])\n",
- " if x[\"properties\"][\"change\"] is not None\n",
- " else \"transparent\",\n",
- " \"color\": \"black\",\n",
- " \"fillOpacity\": 0.4,\n",
- " },\n",
- " tooltip=tooltip,\n",
- " popup=popup,\n",
- ").add_to(m)\n",
- "\n",
- "colormap.add_to(m)\n",
- "\n",
- "m"
+ "We've updated our documentation. You can find the new version of this notebook here:\n",
+ "https://python-visualization.github.io/folium/latest/user_guide/geojson/geojson_popup_and_tooltip.html"
]
}
],
diff --git a/examples/GeodedeticImageOverlay.ipynb b/examples/GeodedeticImageOverlay.ipynb
index 348c553ce..dd9580857 100644
--- a/examples/GeodedeticImageOverlay.ipynb
+++ b/examples/GeodedeticImageOverlay.ipynb
@@ -1,206 +1,14 @@
{
"cells": [
- {
- "cell_type": "code",
- "execution_count": 1,
- "metadata": {},
- "outputs": [],
- "source": [
- "import numpy as np\n",
- "\n",
- "\n",
- "def sample_data(shape=(73, 145)):\n",
- " nlats, nlons = shape\n",
- " lats = np.linspace(-np.pi / 2, np.pi / 2, nlats)\n",
- " lons = np.linspace(0, 2 * np.pi, nlons)\n",
- " lons, lats = np.meshgrid(lons, lats)\n",
- " wave = 0.75 * (np.sin(2 * lats) ** 8) * np.cos(4 * lons)\n",
- " mean = 0.5 * np.cos(2 * lats) * ((np.sin(2 * lats)) ** 2 + 2)\n",
- "\n",
- " lats = np.rad2deg(lats)\n",
- " lons = np.rad2deg(lons)\n",
- " data = wave + mean\n",
- "\n",
- " return lons, lats, data\n",
- "\n",
- "\n",
- "lon, lat, data = sample_data(shape=(73, 145))\n",
- "lon -= 180"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 2,
- "metadata": {},
- "outputs": [],
- "source": [
- "%matplotlib inline\n",
- "\n",
- "import matplotlib\n",
- "\n",
- "cm = matplotlib.cm.get_cmap(\"cubehelix\")\n",
- "\n",
- "normed_data = (data - data.min()) / (data.max() - data.min())\n",
- "colored_data = cm(normed_data)"
- ]
- },
{
"cell_type": "markdown",
- "metadata": {},
"source": [
- "# Bad"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 3,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "Make this Notebook Trusted to load map: File -> Trust Notebook
"
- ],
- "text/plain": [
- ""
- ]
- },
- "execution_count": 3,
- "metadata": {},
- "output_type": "execute_result"
- }
+ "We've updated our documentation. You can find the new version of this notebook here:\n",
+ "https://python-visualization.github.io/folium/latest/advanced_guide/geodedetic_image_overlay.html"
],
- "source": [
- "import folium\n",
- "\n",
- "\n",
- "m = folium.Map(location=[lat.mean(), lon.mean()], zoom_start=1)\n",
- "\n",
- "folium.raster_layers.ImageOverlay(\n",
- " image=colored_data,\n",
- " bounds=[[lat.min(), lon.min()], [lat.max(), lon.max()]],\n",
- " opacity=0.25,\n",
- ").add_to(m)\n",
- "\n",
- "m"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "# Good"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 4,
- "metadata": {},
- "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(location=[lat.mean(), lon.mean()], zoom_start=1)\n",
- "\n",
- "folium.raster_layers.ImageOverlay(\n",
- " image=colored_data,\n",
- " bounds=[[lat.min(), lon.min()], [lat.max(), lon.max()]],\n",
- " mercator_project=True,\n",
- " opacity=0.25,\n",
- ").add_to(m)\n",
- "\n",
- "\n",
- "m"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "# Same as above but with cartopy"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 5,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "Make this Notebook Trusted to load map: File -> Trust Notebook
"
- ],
- "text/plain": [
- ""
- ]
- },
- "execution_count": 5,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "import cartopy.crs as ccrs\n",
- "from cartopy.img_transform import warp_array\n",
- "\n",
- "source_extent = [lon.min(), lon.max(), lat.min(), lat.max()]\n",
- "\n",
- "new_data = warp_array(\n",
- " colored_data,\n",
- " target_proj=ccrs.GOOGLE_MERCATOR,\n",
- " source_proj=ccrs.PlateCarree(),\n",
- " target_res=data.shape,\n",
- " source_extent=source_extent,\n",
- " target_extent=None,\n",
- " mask_extrapolated=False,\n",
- ")\n",
- "\n",
- "\n",
- "m = folium.Map(location=[lat.mean(), lon.mean()], zoom_start=1)\n",
- "\n",
- "folium.raster_layers.ImageOverlay(\n",
- " image=new_data[0],\n",
- " bounds=[[lat.min(), lon.min()], [lat.max(), lon.max()]],\n",
- " opacity=0.25,\n",
- ").add_to(m)\n",
- "\n",
- "m"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "TODO: Try [rasterio](https://github.com/mapbox/rasterio/blob/ca75cf0a842943c1b3da4522e6ea3500215130fd/docs/reproject.rst). Rasterio can warp images and arrays."
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "# Compare to original"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "From https://scitools.org.uk/cartopy/docs/latest/gallery/waves.html\n",
- "\n",
- "![](https://scitools.org.uk/cartopy/docs/latest/_images/sphx_glr_waves_001.png)"
- ]
+ "metadata": {
+ "collapsed": false
+ }
}
],
"metadata": {
diff --git a/examples/Geopandas_and_geo_interface.ipynb b/examples/Geopandas_and_geo_interface.ipynb
index 93a870819..3225e08a5 100644
--- a/examples/Geopandas_and_geo_interface.ipynb
+++ b/examples/Geopandas_and_geo_interface.ipynb
@@ -2,375 +2,14 @@
"cells": [
{
"cell_type": "markdown",
- "metadata": {},
- "source": [
- "# How to draw a GeoPandas.GeoDataFrame into folium\n",
- "\n",
- "GeoPandas is a project to add support for geographic data to [pandas](http://pandas.pydata.org) objects.\n",
- "(See https://github.com/geopandas/geopandas)\n",
- "\n",
- "It provides (among other cool things) a `GeoDataFrame` object that represents a Feature collection.\n",
- "When you have one, you may be willing to use it on a folium map. Here's the simplest way to do so."
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "In this example, we'll use the same file as GeoPandas demo ; it's containing\n",
- "[the boroughs of New York City](http://www.nyc.gov/html/dcp/download/bytes/nybb_14aav.zip)."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 1,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " BoroCode \n",
- " BoroName \n",
- " Shape_Leng \n",
- " Shape_Area \n",
- " geometry \n",
- " \n",
- " \n",
- " \n",
- " \n",
- " 0 \n",
- " 5 \n",
- " Staten Island \n",
- " 330454.175933 \n",
- " 1.623847e+09 \n",
- " MULTIPOLYGON (((970217.022 145643.332, 970227.... \n",
- " \n",
- " \n",
- " 1 \n",
- " 3 \n",
- " Brooklyn \n",
- " 741227.337073 \n",
- " 1.937810e+09 \n",
- " MULTIPOLYGON (((1021176.479 151374.797, 102100... \n",
- " \n",
- " \n",
- " 2 \n",
- " 4 \n",
- " Queens \n",
- " 896875.396449 \n",
- " 3.045079e+09 \n",
- " MULTIPOLYGON (((1029606.077 156073.814, 102957... \n",
- " \n",
- " \n",
- " 3 \n",
- " 1 \n",
- " Manhattan \n",
- " 358400.912836 \n",
- " 6.364308e+08 \n",
- " MULTIPOLYGON (((981219.056 188655.316, 980940.... \n",
- " \n",
- " \n",
- " 4 \n",
- " 2 \n",
- " Bronx \n",
- " 464475.145651 \n",
- " 1.186822e+09 \n",
- " MULTIPOLYGON (((1012821.806 229228.265, 101278... \n",
- " \n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- " BoroCode BoroName Shape_Leng Shape_Area \\\n",
- "0 5 Staten Island 330454.175933 1.623847e+09 \n",
- "1 3 Brooklyn 741227.337073 1.937810e+09 \n",
- "2 4 Queens 896875.396449 3.045079e+09 \n",
- "3 1 Manhattan 358400.912836 6.364308e+08 \n",
- "4 2 Bronx 464475.145651 1.186822e+09 \n",
- "\n",
- " geometry \n",
- "0 MULTIPOLYGON (((970217.022 145643.332, 970227.... \n",
- "1 MULTIPOLYGON (((1021176.479 151374.797, 102100... \n",
- "2 MULTIPOLYGON (((1029606.077 156073.814, 102957... \n",
- "3 MULTIPOLYGON (((981219.056 188655.316, 980940.... \n",
- "4 MULTIPOLYGON (((1012821.806 229228.265, 101278... "
- ]
- },
- "execution_count": 1,
- "metadata": {},
- "output_type": "execute_result"
+ "metadata": {
+ "pycharm": {
+ "name": "#%% md\n"
}
- ],
- "source": [
- "import geopandas\n",
- "\n",
- "url = (\n",
- " \"https://raw.githubusercontent.com/python-visualization/folium/main/examples/data\"\n",
- ")\n",
- "nybb = f\"{url}/nybb.zip\"\n",
- "boros = geopandas.read_file(nybb)\n",
- "\n",
- "boros"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "To create a map with these features, simply put them in a `GeoJson`:"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 2,
- "metadata": {},
- "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": [
- "import folium\n",
- "\n",
- "\n",
- "m = folium.Map([40.7, -74], zoom_start=10, tiles=\"cartodbpositron\")\n",
- "\n",
- "folium.GeoJson(boros).add_to(m)\n",
- "\n",
- "m"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "Quite easy.\n",
- "\n",
- "Well, you can also take advantage of your `GeoDataFrame` structure to set the style of the data. For this, just create a column `style` containing each feature's style in a dictionary."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 3,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " BoroCode \n",
- " BoroName \n",
- " Shape_Leng \n",
- " Shape_Area \n",
- " geometry \n",
- " style \n",
- " \n",
- " \n",
- " \n",
- " \n",
- " 0 \n",
- " 5 \n",
- " Staten Island \n",
- " 330454.175933 \n",
- " 1.623847e+09 \n",
- " MULTIPOLYGON (((970217.022 145643.332, 970227.... \n",
- " {'fillColor': '#ff0000', 'weight': 2, 'color':... \n",
- " \n",
- " \n",
- " 1 \n",
- " 3 \n",
- " Brooklyn \n",
- " 741227.337073 \n",
- " 1.937810e+09 \n",
- " MULTIPOLYGON (((1021176.479 151374.797, 102100... \n",
- " {'fillColor': '#00ff00', 'weight': 2, 'color':... \n",
- " \n",
- " \n",
- " 2 \n",
- " 4 \n",
- " Queens \n",
- " 896875.396449 \n",
- " 3.045079e+09 \n",
- " MULTIPOLYGON (((1029606.077 156073.814, 102957... \n",
- " {'fillColor': '#0000ff', 'weight': 2, 'color':... \n",
- " \n",
- " \n",
- " 3 \n",
- " 1 \n",
- " Manhattan \n",
- " 358400.912836 \n",
- " 6.364308e+08 \n",
- " MULTIPOLYGON (((981219.056 188655.316, 980940.... \n",
- " {'fillColor': '#ffff00', 'weight': 2, 'color':... \n",
- " \n",
- " \n",
- " 4 \n",
- " 2 \n",
- " Bronx \n",
- " 464475.145651 \n",
- " 1.186822e+09 \n",
- " MULTIPOLYGON (((1012821.806 229228.265, 101278... \n",
- " {'fillColor': '#00ffff', 'weight': 2, 'color':... \n",
- " \n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- " BoroCode BoroName Shape_Leng Shape_Area \\\n",
- "0 5 Staten Island 330454.175933 1.623847e+09 \n",
- "1 3 Brooklyn 741227.337073 1.937810e+09 \n",
- "2 4 Queens 896875.396449 3.045079e+09 \n",
- "3 1 Manhattan 358400.912836 6.364308e+08 \n",
- "4 2 Bronx 464475.145651 1.186822e+09 \n",
- "\n",
- " geometry \\\n",
- "0 MULTIPOLYGON (((970217.022 145643.332, 970227.... \n",
- "1 MULTIPOLYGON (((1021176.479 151374.797, 102100... \n",
- "2 MULTIPOLYGON (((1029606.077 156073.814, 102957... \n",
- "3 MULTIPOLYGON (((981219.056 188655.316, 980940.... \n",
- "4 MULTIPOLYGON (((1012821.806 229228.265, 101278... \n",
- "\n",
- " style \n",
- "0 {'fillColor': '#ff0000', 'weight': 2, 'color':... \n",
- "1 {'fillColor': '#00ff00', 'weight': 2, 'color':... \n",
- "2 {'fillColor': '#0000ff', 'weight': 2, 'color':... \n",
- "3 {'fillColor': '#ffff00', 'weight': 2, 'color':... \n",
- "4 {'fillColor': '#00ffff', 'weight': 2, 'color':... "
- ]
- },
- "execution_count": 3,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "boros[\"style\"] = [\n",
- " {\"fillColor\": \"#ff0000\", \"weight\": 2, \"color\": \"black\"},\n",
- " {\"fillColor\": \"#00ff00\", \"weight\": 2, \"color\": \"black\"},\n",
- " {\"fillColor\": \"#0000ff\", \"weight\": 2, \"color\": \"black\"},\n",
- " {\"fillColor\": \"#ffff00\", \"weight\": 2, \"color\": \"black\"},\n",
- " {\"fillColor\": \"#00ffff\", \"weight\": 2, \"color\": \"black\"},\n",
- "]\n",
- "\n",
- "boros"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 4,
- "metadata": {},
- "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([40.7, -74], zoom_start=10, tiles=\"cartodbpositron\")\n",
- "\n",
- "folium.GeoJson(boros).add_to(m)\n",
- "\n",
- "m"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "Folium should work with any object that implements the `__geo_interface__` but be aware that sometimes you may need to convert your data to `epsg='4326'` before sending it to `folium`."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 5,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "Make this Notebook Trusted to load map: File -> Trust Notebook
"
- ],
- "text/plain": [
- ""
- ]
- },
- "execution_count": 5,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ },
"source": [
- "import fiona\n",
- "import shapely\n",
- "\n",
- "fname = f\"{url}/2014_08_05_farol.gpx\"\n",
- "with fiona.open(fname, \"r\", layer=\"tracks\") as records:\n",
- " tracks = [shapely.geometry.shape(record[\"geometry\"]) for record in records]\n",
- "\n",
- "track = tracks[0]\n",
- "\n",
- "m = folium.Map(tiles=\"cartodbpositron\")\n",
- "folium.GeoJson(track).add_to(m)\n",
- "\n",
- "m.fit_bounds(m.get_bounds())\n",
- "\n",
- "m"
+ "We've updated our documentation. You can find the new version of this notebook here:\n",
+ "https://python-visualization.github.io/folium/latest/user_guide/geojson/geopandas_and_geo_interface.html"
]
}
],
diff --git a/examples/Heatmap.ipynb b/examples/Heatmap.ipynb
index 1e7082371..8034f621b 100644
--- a/examples/Heatmap.ipynb
+++ b/examples/Heatmap.ipynb
@@ -1,48 +1,15 @@
{
"cells": [
{
- "cell_type": "code",
- "execution_count": 1,
- "metadata": {},
- "outputs": [],
- "source": [
- "import numpy as np\n",
- "\n",
- "\n",
- "data = (\n",
- " np.random.normal(size=(100, 3)) * np.array([[1, 1, 1]]) + np.array([[48, 5, 1]])\n",
- ").tolist()"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 2,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "Make this Notebook Trusted to load map: File -> Trust Notebook
"
- ],
- "text/plain": [
- ""
- ]
- },
- "execution_count": 2,
- "metadata": {},
- "output_type": "execute_result"
+ "cell_type": "markdown",
+ "metadata": {
+ "pycharm": {
+ "name": "#%% md\n"
}
- ],
+ },
"source": [
- "import folium\n",
- "from folium.plugins import HeatMap\n",
- "\n",
- "\n",
- "m = folium.Map([48.0, 5.0], tiles=\"stamentoner\", zoom_start=6)\n",
- "\n",
- "HeatMap(data).add_to(m)\n",
- "\n",
- "m"
+ "We've updated our documentation. You can find the new version of this notebook here:\n",
+ "https://python-visualization.github.io/folium/latest/user_guide/plugins/heatmap.html"
]
}
],
diff --git a/examples/flask_example.py b/examples/flask_example.py
index 47d4273cf..9491936e8 100644
--- a/examples/flask_example.py
+++ b/examples/flask_example.py
@@ -1,92 +1,4 @@
-""" flask_example.py
-
- Required packages:
- - flask
- - folium
-
- Usage:
-
- Start the flask server by running:
-
- $ python flask_example.py
-
- And then head to http://127.0.0.1:5000/ in your browser to see the map displayed
-
"""
-
-from flask import Flask, render_template_string
-
-import folium
-
-app = Flask(__name__)
-
-
-@app.route("/")
-def fullscreen():
- """Simple example of a fullscreen map."""
- m = folium.Map()
- return m.get_root().render()
-
-
-@app.route("/iframe")
-def iframe():
- """Embed a map as an iframe on a page."""
- m = folium.Map()
-
- # set the iframe width and height
- m.get_root().width = "800px"
- m.get_root().height = "600px"
- iframe = m.get_root()._repr_html_()
-
- return render_template_string(
- """
-
-
-
-
- Using an iframe
- {{ iframe|safe }}
-
-
- """,
- iframe=iframe,
- )
-
-
-@app.route("/components")
-def components():
- """Extract map components and put those on a page."""
- m = folium.Map(
- width=800,
- height=600,
- )
-
- m.get_root().render()
- header = m.get_root().header.render()
- body_html = m.get_root().html.render()
- script = m.get_root().script.render()
-
- return render_template_string(
- """
-
-
-
- {{ header|safe }}
-
-
- Using components
- {{ body_html|safe }}
-
-
-
- """,
- header=header,
- body_html=body_html,
- script=script,
- )
-
-
-if __name__ == "__main__":
- app.run(debug=True)
+We've updated our documentation. You can find the new version of this example here:
+https://python-visualization.github.io/folium/latest/advanced_guide/flask.html
+"""