{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# HeatMapWithTime Plugin" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In this example we show the most basic usage of the HeatMapWithTime plugin.\n", "\n", "We generate a random set of points with lat/lon coordinates to draw on the map, and then move these points slowly in a random direction to simulate a time dimension. The points are aranged into a list of sets of data to draw." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import folium\n", "import folium.plugins as plugins\n", "import numpy as np\n", "\n", "np.random.seed(3141592)\n", "initial_data = (\n", " np.random.normal(size=(100, 2)) * np.array([[1, 1]]) +\n", " np.array([[48, 5]])\n", ")\n", "\n", "move_data = np.random.normal(size=(100, 2)) * 0.01\n", "\n", "data = [(initial_data + move_data * i).tolist() for i in range(100)]" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "m = folium.Map([48., 5.], tiles='stamentoner', zoom_start=6)\n", "\n", "hm = plugins.HeatMapWithTime(data)\n", "\n", "hm.add_to(m)\n", "\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now we show that the time index can be specified, allowing a more meaningful representation of what the time steps mean. We also enable the 'auto_play' option and change the maximum opacity. See the docmentation for a full list of options that can be used." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "from datetime import datetime, timedelta\n", "\n", "\n", "time_index = [\n", " (datetime.now() + k * timedelta(1)).strftime('%Y-%m-%d') for\n", " k in range(len(data))\n", "]" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "m = folium.Map([48., 5.], tiles='stamentoner', zoom_start=6)\n", "\n", "hm = plugins.HeatMapWithTime(\n", " data,\n", " index=time_index,\n", " auto_play=True,\n", " max_opacity=0.3\n", ")\n", "\n", "hm.add_to(m)\n", "\n", "m" ] } ], "metadata": { "anaconda-cloud": {}, "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.2" } }, "nbformat": 4, "nbformat_minor": 1 }