{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "180cd7db-fad3-4044-8026-f9239ed93389", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from lets_plot import *\n", "from lets_plot.bistro import *\n", "import pandas as pd\n", "LetsPlot.setup_html()" ] }, { "cell_type": "code", "execution_count": 2, "id": "1bac5812-fbf1-4467-aad5-3ad978c2e807", "metadata": {}, "outputs": [], "source": [ "df = {\n", " 'x': [1],\n", " 'y': [1],\n", " 's': [1]\n", "}" ] }, { "cell_type": "markdown", "id": "3d375e63-23d1-4df9-a767-ec05733951a3", "metadata": {}, "source": [ "### Without scale" ] }, { "cell_type": "code", "execution_count": 3, "id": "f5f566a6-b075-4fee-8893-cb5df7f4e190", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ggplot(df, aes('x','y')) + geom_point() + ggtb()" ] }, { "cell_type": "markdown", "id": "a48530bb-6ed6-4396-9d8c-556c836c54db", "metadata": {}, "source": [ "### `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×**." ] }, { "cell_type": "markdown", "id": "8ca736e1-150f-4409-9d1c-d16ae7a3eea5", "metadata": {}, "source": [ "#### `size_zoomin=0` zoom in disabled" ] }, { "cell_type": "code", "execution_count": 4, "id": "bd961d3d-abb3-4a8c-a094-7d1d1c0e7ee5", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ggplot(df, aes('x','y')) + geom_point() + ggtb(size_zoomin=0)" ] }, { "cell_type": "markdown", "id": "61847cbb-9edb-4dfc-bae1-86fa5a9989c1", "metadata": {}, "source": [ "#### `size_zoomin=-1` unlimited zoom in" ] }, { "cell_type": "code", "execution_count": 5, "id": "4986f872-4ac4-4b86-8e65-55c719dc3018", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ggplot(df, aes('x','y')) + geom_point() + ggtb(size_zoomin=-1)" ] }, { "cell_type": "markdown", "id": "e3610c38-9d57-4989-b477-53ecdb2c8bb0", "metadata": {}, "source": [ "#### `size_zoomin=3` zoom is capped at three times. " ] }, { "cell_type": "code", "execution_count": 6, "id": "2f8b24d8-60de-48ef-8b71-5c7e8838d307", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ggplot(df, aes('x','y')) + geom_point() + ggtb(size_zoomin=3)" ] }, { "cell_type": "markdown", "id": "8051e772-d078-4751-8653-3c92f958e19c", "metadata": {}, "source": [ "#### Illegal `size_zoomin` value" ] }, { "cell_type": "code", "execution_count": 7, "id": "1453fefc-9431-44a6-9ca9-5a1535328b76", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ggplot(df, aes('x','y')) + geom_point() + ggtb(size_zoomin=-3)" ] }, { "cell_type": "markdown", "id": "5b39dc89-e5dc-43f9-87a6-eaf0f5baad34", "metadata": {}, "source": [ "### `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": "markdown", "id": "641cac64-91e9-4875-a9b3-41068911ee37", "metadata": {}, "source": [ "#### `size_basis=\"x\"` \n", "Try using rubber-band zoom along the x axis only (and then along the y axis) to see the effect." ] }, { "cell_type": "code", "execution_count": 8, "id": "48ee96fc-53f2-45c1-9c10-451ad960c932", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ggplot(df, aes('x','y')) + geom_point(size=10) + ggtb(size_basis=\"x\", size_zoomin=-1)" ] }, { "cell_type": "markdown", "id": "09534a61-05c7-4819-a912-05ed138987cf", "metadata": {}, "source": [ "#### `size_basis=\"y\"` " ] }, { "cell_type": "code", "execution_count": 9, "id": "842c972e-7a1a-4834-a779-c7db171744aa", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ggplot(df, aes('x','y')) + geom_point(size=10) + ggtb(size_basis=\"y\", size_zoomin=-1)" ] }, { "cell_type": "markdown", "id": "d175df7b-8d42-43a1-92d3-a26d913b6d58", "metadata": {}, "source": [ "#### `size_basis=\"min\"` " ] }, { "cell_type": "code", "execution_count": 10, "id": "a57da0c9-d53b-4f9e-aec7-d207838f3813", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ggplot(df, aes('x','y')) + geom_point(size=10) + ggtb(size_basis=\"min\", size_zoomin=-1)" ] }, { "cell_type": "markdown", "id": "d37793a9-b506-4e68-8215-5492ac445a50", "metadata": {}, "source": [ "#### `size_basis=\"max\"` default" ] }, { "cell_type": "code", "execution_count": 11, "id": "3f743960-c6d8-44a0-8e82-ec45de6a4b96", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ggplot(df, aes('x','y')) + geom_point(size=10) + ggtb(size_basis=\"max\", size_zoomin=-1)" ] }, { "cell_type": "markdown", "id": "0d5f068e-8026-46ec-8914-1fee727356e9", "metadata": {}, "source": [ "### Support for various size types" ] }, { "cell_type": "markdown", "id": "a7f108ea-5564-4a87-9c9f-d1527725e816", "metadata": {}, "source": [ "#### Default size" ] }, { "cell_type": "code", "execution_count": 12, "id": "191b5337-bcc0-4e09-8dd0-e87390d0ce69", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ggplot(df, aes('x','y')) + geom_point() + ggtb(size_zoomin=-1)" ] }, { "cell_type": "markdown", "id": "2d554844-b123-4a5d-8bc4-4acb4637ecda", "metadata": {}, "source": [ "#### Constant size" ] }, { "cell_type": "code", "execution_count": 13, "id": "e8038993-f2ca-4817-9e4f-2aaf70657fc8", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ggplot(df, aes('x','y')) + geom_point(size=80) + ggtb(size_zoomin=-1)" ] }, { "cell_type": "markdown", "id": "7e75bbb5-9c4e-450a-8e6e-b30d0c1214bf", "metadata": {}, "source": [ "#### Size from Aes" ] }, { "cell_type": "code", "execution_count": 14, "id": "81c6f1ce-4dff-48bc-b2dd-8e0e028e51de", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ggplot(df, aes('x','y')) + geom_point(aes(size='s')) + ggtb(size_zoomin=-1)" ] }, { "cell_type": "markdown", "id": "264fef4d-cd1a-4851-bc54-2b28e3747764", "metadata": {}, "source": [ "#### Constant size with `size_unit`\n", "\n", "Scaling from `ggtb()` is not applied to layers that use `size_unit`. However, it is still applied to the other layers." ] }, { "cell_type": "code", "execution_count": 15, "id": "c4c7119c-5aa9-41e8-8c6e-0274da7bd36c", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ggplot(df, aes('x','y')) + \\\n", " geom_point(size=0.1, size_unit = 'x') + \\\n", " geom_point(size=2, color='red') + \\\n", " ggtb(size_zoomin=-1)" ] }, { "cell_type": "markdown", "id": "bcc5af97-2daa-406f-8c99-89313293cd28", "metadata": {}, "source": [ "### Support `gggrid()`\n", "\n", "`ggtb()` can only be added to the root `gggrid()`. All plots inside will use the same scaling settings. Adding `ggtb()` to plots inside `gggrid()` is not allowed." ] }, { "cell_type": "code", "execution_count": 16, "id": "ffbdd3c6-c67c-4953-8beb-b016d28b75da", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "gggrid(\n", " [\n", " ggplot(df, aes('x','y')) + geom_point(size=10),\n", " gggrid([\n", " ggplot(df, aes('x','y')) + geom_point(size=10),\n", " ggplot(df, aes('x','y')) + geom_point(size=20)\n", " ])\n", " ]\n", ") + ggtb(size_zoomin=-1, size_basis=\"x\")" ] }, { "cell_type": "markdown", "id": "a79fcb1e-e692-46f9-96e8-e7098dcf897e", "metadata": {}, "source": [ "### Support `facet_wrap()`" ] }, { "cell_type": "code", "execution_count": 17, "id": "746e8fd3-0c40-4b34-98f3-a6c72308c1db", "metadata": {}, "outputs": [], "source": [ "mpg = pd.read_csv('https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/mpg2.csv')" ] }, { "cell_type": "code", "execution_count": 18, "id": "750546be-3101-4035-a70a-b80eb6ec78fe", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p = (\n", " ggplot(mpg, \n", " aes('engine horsepower', 'miles per gallon', \n", " color=as_discrete('origin of car',order=-1)))\n", " + geom_point()\n", " + theme_grey() + ggtitle('Efficiency vs Engine Horsepower')\n", ")\n", "p" ] }, { "cell_type": "code", "execution_count": 19, "id": "0d97d20f-d05a-4882-ade8-7114ee958af9", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p + facet_wrap(['origin of car', 'number of cylinders'], order=[-1, 1], ncol=3) + ggtb(size_zoomin=3)" ] }, { "cell_type": "code", "execution_count": null, "id": "8e72369e-4ab8-420e-8290-d737131c4d68", "metadata": {}, "outputs": [], "source": [] } ], "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.20" } }, "nbformat": 4, "nbformat_minor": 5 }