{ "cells": [ { "cell_type": "markdown", "id": "eec756ff-2fe9-4267-bfd3-829d7d19a6ba", "metadata": {}, "source": [ "# `ggtb()`: `size_zoomin` and `size_basis` Parameters for Geometry Scaling\n", "\n", "## `size_zoomin` parameter\n", "\n", "The `size_zoomin` parameter accepts an integer value:\n", "\n", "* `0` — zoom in disabled (default)\n", "* `-1` — unlimited zoom in\n", "* Any other positive number — maximum zoom-in limit. For example, `2` means the geometry can be scaled up to **2×**.\n", "\n", "## `size_basis` parameter\n", "\n", "The `size_basis` parameter accepts a string value: `x`, `y`, `min`, or `max` (default: `max`).\n", "It defines which axis is used to calculate the scaling factor.\n", "\n", "* `x` and `y` specify the corresponding axis.\n", "* `min` uses the smaller scaling factor.\n", "* `max` uses the larger scaling factor." ] }, { "cell_type": "code", "execution_count": 1, "id": "1c382fab-6e5b-4fdf-b185-c36c386aee18", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from lets_plot import *\n", "import pandas as pd\n", "LetsPlot.setup_html()" ] }, { "cell_type": "markdown", "id": "6c0c8116-990c-403c-bf49-696247f642a3", "metadata": {}, "source": [ "#### Enable 'Unlimited' Zoom\n" ] }, { "cell_type": "code", "execution_count": 2, "id": "c287276a-2732-4bbd-b07d-33f32737a5f9", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ggplot() + geom_point(x=0, y=0, size=10) + ggtb(\n", " size_zoomin=-1 # <-- Point size can grow without limits.\n", ")" ] }, { "cell_type": "markdown", "id": "da9be487-a3b4-4a1a-b6b3-70d1fd01f2c0", "metadata": {}, "source": [ "#### Limit Maximum Zoom to 3× Original Size" ] }, { "cell_type": "code", "execution_count": 3, "id": "1079f295-4c9a-415a-b230-85226422198b", "metadata": {}, "outputs": [], "source": [ "mpg = pd.read_csv('https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/mpg2.csv')" ] }, { "cell_type": "code", "execution_count": 4, "id": "6379f40f-53d3-47c1-9113-0d7493262490", "metadata": {}, "outputs": [], "source": [ "p = (\n", " ggplot(mpg, \n", " aes('engine horsepower', 'miles per gallon', \n", " color=as_discrete('origin of car',order=-1))) \n", " + theme_grey() + ggtitle('Efficiency vs Engine Horsepower')\n", ")" ] }, { "cell_type": "code", "execution_count": 5, "id": "4a11b4c2-3857-476a-aebf-a23de27ac2e5", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p + geom_jitter(seed=42) + ggtb(\n", " size_zoomin=3 # <-- Point size can grow to 3x of the original size max.\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.9.23" } }, "nbformat": 4, "nbformat_minor": 5 }