{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Set up for JupyterLite\n", "try:\n", " import piplite\n", " await piplite.install('ipyleaflet')\n", "except ImportError:\n", " pass" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from ipyleaflet import Map, Heatmap\n", "from random import uniform\n", "import time" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def create_random_data(length):\n", " \"Return a list of some random lat/lon/value triples.\"\n", " return [\n", " [uniform(-80, 80), uniform(-180, 180), uniform(0, 1000)] for i in range(length)\n", " ]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = Map(center=[0, 0], zoom=2)\n", "m" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "heat = Heatmap(locations=create_random_data(1000), radius=20, blur=10)\n", "m.add(heat)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "for i in range(100):\n", " heat.locations = create_random_data(1000)\n", " time.sleep(0.1)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "heat.radius = 30" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "heat.blur = 50" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "heat.max = 0.5" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "heat.gradient = {0.4: \"red\", 0.6: \"yellow\", 0.7: \"lime\", 0.8: \"cyan\", 1.0: \"blue\"}" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "heat.locations = [\n", " [uniform(-80, 80), uniform(-180, 180), uniform(0, 1000)] for i in range(1000)\n", "]" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.10.5" } }, "nbformat": 4, "nbformat_minor": 4 }