{ "cells": [ { "cell_type": "markdown", "id": "3b3c31f8-7f05-4b50-be2d-cfd85781c62b", "metadata": {}, "source": [ "# Text Geoms\n", "\n", "Text geoms are useful for labeling plots. They can be used by themselves or in combination with other geoms. \n", "\n", "1. [`geom_text()`/`geom_label()`](#1.-geom_text()/geom_label())\n", "\n", "2. [The `label_format` Parameter](#2.-The-label_format-Parameter)\n", "\n", "3. [Support of Multiple Lines](#3.-Support-of-Multiple-Lines)\n", "\n", " 3.1. [Change Lineheight](#3.1.-Change-Lineheight)\n", "\n", "4. [Rotation and Alignment](#4.-Rotation-and-Alignment)\n", "\n", " 4.1. [Adjust Position by Nudging a Given Offset](#4.1.-Adjust-Position-by-Nudging-a-Given-Offset)\n", "\n", " 4.2. [Move Text - Use `position_nudge`](#4.2.-Move-Text---Use-position_nudge)\n", "\n", " 4.3. [Move Text - Use `nudge_y` Parameter](#4.3.-Move-Text---Use-nudge_y-Parameter)\n", "\n", " 4.4. [Justification: `inward` and `outward`](#4.4.-Justification:-inward-and-outward)\n", "\n", "5. [GeoDataFrame in `geom_text()`/`geom_label()`](#5.-GeoDataFrame-in-geom_text()/geom_label())\n", "\n", "6. [Text on Livemap](#6.-Text-on-Livemap)\n" ] }, { "cell_type": "code", "execution_count": 1, "id": "victorian-aberdeen", "metadata": { "execution": { "iopub.execute_input": "2024-04-26T12:07:10.478600Z", "iopub.status.busy": "2024-04-26T12:07:10.478600Z", "iopub.status.idle": "2024-04-26T12:07:11.506807Z", "shell.execute_reply": "2024-04-26T12:07:11.506095Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "The geodata is provided by © OpenStreetMap contributors and is made available here under the Open Database License (ODbL).\n" ] } ], "source": [ "from itertools import product\n", "\n", "import pandas as pd\n", "\n", "from lets_plot import *\n", "from lets_plot import tilesets\n", "from lets_plot.geo_data import *\n", "from lets_plot.mapping import as_discrete" ] }, { "cell_type": "code", "execution_count": 2, "id": "61246a0a-c42d-42f7-a0d7-0f68909ee627", "metadata": { "execution": { "iopub.execute_input": "2024-04-26T12:07:11.506807Z", "iopub.status.busy": "2024-04-26T12:07:11.506807Z", "iopub.status.idle": "2024-04-26T12:07:11.521934Z", "shell.execute_reply": "2024-04-26T12:07:11.521934Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "LetsPlot.setup_html()" ] }, { "cell_type": "markdown", "id": "0b1cec35-d9b0-47a2-a9f1-5866950ca56f", "metadata": {}, "source": [ "# 1. `geom_text()`/`geom_label()`\n", "\n", "- `geom_text()` adds a text directly to the plot.\n", "- `geom_label()` adds a text directly to the plot with a rectangle behind the text, making it easier to read." ] }, { "cell_type": "code", "execution_count": 3, "id": "differential-tsunami", "metadata": { "execution": { "iopub.execute_input": "2024-04-26T12:07:11.521934Z", "iopub.status.busy": "2024-04-26T12:07:11.521934Z", "iopub.status.idle": "2024-04-26T12:07:11.553371Z", "shell.execute_reply": "2024-04-26T12:07:11.553371Z" } }, "outputs": [ { "data": { "text/html": [ " \n", " " ], "text/plain": [ "\n", " | Unnamed: 0 | \n", "manufacturer | \n", "model | \n", "displ | \n", "year | \n", "cyl | \n", "trans | \n", "drv | \n", "cty | \n", "hwy | \n", "fl | \n", "class | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "1 | \n", "audi | \n", "a4 | \n", "1.8 | \n", "1999 | \n", "4 | \n", "auto(l5) | \n", "f | \n", "18 | \n", "29 | \n", "p | \n", "compact | \n", "
1 | \n", "2 | \n", "audi | \n", "a4 | \n", "1.8 | \n", "1999 | \n", "4 | \n", "manual(m5) | \n", "f | \n", "21 | \n", "29 | \n", "p | \n", "compact | \n", "
2 | \n", "3 | \n", "audi | \n", "a4 | \n", "2.0 | \n", "2008 | \n", "4 | \n", "manual(m6) | \n", "f | \n", "20 | \n", "31 | \n", "p | \n", "compact | \n", "
3 | \n", "4 | \n", "audi | \n", "a4 | \n", "2.0 | \n", "2008 | \n", "4 | \n", "auto(av) | \n", "f | \n", "21 | \n", "30 | \n", "p | \n", "compact | \n", "
4 | \n", "5 | \n", "audi | \n", "a4 | \n", "2.8 | \n", "1999 | \n", "6 | \n", "auto(l5) | \n", "f | \n", "16 | \n", "26 | \n", "p | \n", "compact | \n", "