{ "cells": [ { "cell_type": "markdown", "id": "b0b00c5e-dcef-4bba-a7b8-92ca3320063b", "metadata": {}, "source": [ "# `Zoom` and `Pan` Interactivity\n", "\n", "Use the `ggtb()` function to enable `Pan` and `Zoom` interactivity on a chart.\n", "\n", "This function adds a toolbar containing three tool-buttons: pan, rubber-band zoom, and center-point zoom. \n", "\n", "Each tool uses **mouse-drag** for its specific functionality. Additionally, the **mouse wheel** can be used for zooming in and out, regardless of the selected tool.\n", "\n", "The behavior of these tools adapts to the initial mouse drag direction:\n", "- Near-horizontal drag: restricts panning to horizontal movement or creates a vertical band for zooming.\n", "- Near-vertical drag: limits panning to vertical movement or produces a horizontal band for zooming.\n", "- Diagonal drag: allows panning in any direction or creates a rectangular area for zooming.\n", "\n", "**Double-clicking** anywhere on the plot resets it to its original coordinates, regardless of whether a tool is selected or not.\n", "\n", "Click the 4th button, `Reset`, to reset the plot and tools to their original state.\n" ] }, { "cell_type": "code", "execution_count": 1, "id": "c805f48f-bd4a-47ce-b687-db299e29132d", "metadata": { "execution": { "iopub.execute_input": "2025-07-17T17:06:06.660940Z", "iopub.status.busy": "2025-07-17T17:06:06.660741Z", "iopub.status.idle": "2025-07-17T17:06:06.663569Z", "shell.execute_reply": "2025-07-17T17:06:06.663383Z" } }, "outputs": [], "source": [ "import pandas as pd\n", "\n", "from lets_plot import *" ] }, { "cell_type": "code", "execution_count": 2, "id": "b846c5b9-5f3d-46a6-95f2-849c6ffd18cf", "metadata": { "execution": { "iopub.execute_input": "2025-07-17T17:06:06.664505Z", "iopub.status.busy": "2025-07-17T17:06:06.664392Z", "iopub.status.idle": "2025-07-17T17:06:06.666177Z", "shell.execute_reply": "2025-07-17T17:06:06.666014Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "LetsPlot.setup_html()" ] }, { "cell_type": "code", "execution_count": 3, "id": "113c62dd-177c-4090-b305-6ac953e34dd8", "metadata": { "execution": { "iopub.execute_input": "2025-07-17T17:06:06.666978Z", "iopub.status.busy": "2025-07-17T17:06:06.666908Z", "iopub.status.idle": "2025-07-17T17:06:07.239480Z", "shell.execute_reply": "2025-07-17T17:06:07.239286Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(234, 12)\n" ] }, { "data": { "text/html": [ "\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", "