{ "cells": [ { "cell_type": "markdown", "id": "cd6ed382-76f2-4d90-ab8c-a09d18681822", "metadata": {}, "source": [ "# Working With Scientific Notation\n", "\n", "The `exponent_format` parameter in the `theme(...)` function can be used to configure the way \"exponent notation\" looks like on plot.\n", "\n", "Available values:\n", "\n", "- `'e'` for \"e\" notation (e.g. 1e+6);\n", "- `'pow_full'` for \"power\" notation (e.g. $1 \\cdot 10^6$). This will enable superscript formatting for the exponent;\n", "- `'pow'` works as `'pow_full'` but will shorten powers of 10 (e.g. $10^6$ instead of $1 \\cdot 10^6$).\n", "\n", "The \"exponent format\" is automatically applied to each value formatted in scientific notation, regardless whether the format is user-defined or chosen automatically based on the data. This format affects every part of a plot, including geoms, scales, labels, and tooltips." ] }, { "cell_type": "code", "execution_count": 1, "id": "440ed621-4a10-4f0a-8f39-36f05afb56b5", "metadata": { "execution": { "iopub.execute_input": "2025-11-05T13:46:59.884168Z", "iopub.status.busy": "2025-11-05T13:46:59.884059Z", "iopub.status.idle": "2025-11-05T13:46:59.887342Z", "shell.execute_reply": "2025-11-05T13:46:59.887096Z" } }, "outputs": [], "source": [ "import pandas as pd\n", "\n", "from lets_plot import *" ] }, { "cell_type": "code", "execution_count": 2, "id": "f4564dc9-f210-4d74-8f7c-04eacaca2b4d", "metadata": { "execution": { "iopub.execute_input": "2025-11-05T13:46:59.888242Z", "iopub.status.busy": "2025-11-05T13:46:59.888173Z", "iopub.status.idle": "2025-11-05T13:46:59.890061Z", "shell.execute_reply": "2025-11-05T13:46:59.889840Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "LetsPlot.setup_html()" ] }, { "cell_type": "markdown", "id": "409d903e-c78e-482b-bc01-885a002d4796", "metadata": {}, "source": [ "## Exponent Format Customization" ] }, { "cell_type": "code", "execution_count": 3, "id": "e43d5ec9-c65b-4b2e-a143-8d718611c3d5", "metadata": { "execution": { "iopub.execute_input": "2025-11-05T13:46:59.890811Z", "iopub.status.busy": "2025-11-05T13:46:59.890743Z", "iopub.status.idle": "2025-11-05T13:46:59.892528Z", "shell.execute_reply": "2025-11-05T13:46:59.892293Z" } }, "outputs": [], "source": [ "def hourglass_plot(title):\n", " dmin, dmax = -7, 6\n", " values = [10**d for d in range(dmin, dmax + 1)]\n", " return ggplot() + \\\n", " geom_text(aes(y=values, label=values), size=10) + \\\n", " scale_y_continuous(limits=[10**(dmin - 1), 10**(dmax + 1)], trans='log10') + \\\n", " ggtitle(title) + \\\n", " theme_classic()" ] }, { "cell_type": "markdown", "id": "a5b79f37-2693-4f2f-bc0f-a8b5bd44c08f", "metadata": {}, "source": [ "### Switch Exponent Format to Power Degree" ] }, { "cell_type": "code", "execution_count": 4, "id": "cf098257-6060-4d80-b498-2b7c660163b1", "metadata": { "execution": { "iopub.execute_input": "2025-11-05T13:46:59.893212Z", "iopub.status.busy": "2025-11-05T13:46:59.893149Z", "iopub.status.idle": "2025-11-05T13:46:59.922605Z", "shell.execute_reply": "2025-11-05T13:46:59.922225Z" } }, "outputs": [ { "data": { "text/html": [ " \n", " " ], "text/plain": [ "| \n", " | Name | \n", "Symbol | \n", "Type | \n", "Weight (ng) | \n", "Radius | \n", "
|---|---|---|---|---|---|
| 0 | \n", "Hydrogen | \n", "H | \n", "Nonmetal | \n", "1.673725e-15 | \n", "0.79 | \n", "
| 1 | \n", "Helium | \n", "He | \n", "Noble Gas | \n", "6.646482e-15 | \n", "0.49 | \n", "
| 2 | \n", "Lithium | \n", "Li | \n", "Alkali Metal | \n", "1.152581e-14 | \n", "2.10 | \n", "
| 3 | \n", "Beryllium | \n", "Be | \n", "Alkaline Earth Metal | \n", "1.496509e-14 | \n", "1.40 | \n", "
| 4 | \n", "Boron | \n", "B | \n", "Metalloid | \n", "1.795210e-14 | \n", "1.20 | \n", "