{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Legend: How to use" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## step 1: create an ipyleaflet map" ] }, { "cell_type": "code", "execution_count": 104, "metadata": {}, "outputs": [], "source": [ "from ipyleaflet import Map, LegendControl" ] }, { "cell_type": "code", "execution_count": 105, "metadata": {}, "outputs": [], "source": [ "mymap = Map(center=(-10,-45), zoom=4)" ] }, { "cell_type": "code", "execution_count": 106, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "e3697c421ece40cd9508549298ad457a", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Map(center=[-10, -45], controls=(ZoomControl(options=['position', 'zoom_in_text', 'zoom_in_title', 'zoom_out_t…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "mymap" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## step 2: create a legend" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "By default, you need to provide at least a dictionnary with pair key=> the label to display and value=> the desired color. By default, it is named 'Legend', but you can pass a name as argument as well. " ] }, { "cell_type": "code", "execution_count": 107, "metadata": {}, "outputs": [], "source": [ "a_legend = LegendControl({\"low\":\"#FAA\", \"medium\":\"#A55\", \"High\":\"#500\"}, name=\"Legend\", position=\"bottomright\")" ] }, { "cell_type": "code", "execution_count": 108, "metadata": {}, "outputs": [], "source": [ "mymap.add_control(a_legend)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Step 3: manipulate Legend" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Name" ] }, { "cell_type": "code", "execution_count": 109, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'Risk'" ] }, "execution_count": 109, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a_legend.name = \"Risk\" ## set name\n", "a_legend.name # get name" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Legend content" ] }, { "cell_type": "code", "execution_count": 110, "metadata": {}, "outputs": [], "source": [ "a_legend.legends = {\"el1\":\"#FAA\", \"el2\":\"#A55\", \"el3\":\"#500\"} #set content\n", "a_legend.legends # get content\n", "\n", "a_legend.add_legend_element(\"el5\",\"#000\") # add a legend element" ] }, { "cell_type": "code", "execution_count": 111, "metadata": {}, "outputs": [], "source": [ "a_legend.remove_legend_element(\"el5\") # remove a legend element" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Positionning" ] }, { "cell_type": "code", "execution_count": 112, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'topright'" ] }, "execution_count": 112, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a_legend.positionning =\"topright\" # set positionning : possible values are topleft, topright, bottomleft, bottomright\n", "a_legend.positionning # get current positionning" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.9" } }, "nbformat": 4, "nbformat_minor": 4 }