{ "cells": [ { "cell_type": "markdown", "id": "federal-highlight", "metadata": {}, "source": [ "# Tooltip Customization API: `disable_splitting()`\n", "\n", "This new function consolidates all \"side\" tooltips (if any) to the general tooltip.\n", "\n", "You can farther customize content of the general tooltip using the `line()` function and other [Tooltip Customization API](https://datalore.jetbrains.com/report/static/dytOfovKhmqMDBibzZhIKl/78LwZrCQ7uHy8P5L0iOcqr).\n" ] }, { "cell_type": "code", "execution_count": 1, "id": "union-mistake", "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "\n", "from lets_plot import *" ] }, { "cell_type": "code", "execution_count": 2, "id": "confirmed-actress", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "LetsPlot.setup_html()" ] }, { "cell_type": "code", "execution_count": 3, "id": "flexible-michigan", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Unnamed: 0manufacturermodeldisplyearcyltransdrvctyhwyflclass
01audia41.819994auto(l5)f1829pcompact
12audia41.819994manual(m5)f2129pcompact
23audia42.020084manual(m6)f2031pcompact
\n", "
" ], "text/plain": [ " Unnamed: 0 manufacturer model displ year cyl trans drv cty hwy \\\n", "0 1 audi a4 1.8 1999 4 auto(l5) f 18 29 \n", "1 2 audi a4 1.8 1999 4 manual(m5) f 21 29 \n", "2 3 audi a4 2.0 2008 4 manual(m6) f 20 31 \n", "\n", " fl class \n", "0 p compact \n", "1 p compact \n", "2 p compact " ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mpg_df = pd.read_csv('https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/mpg.csv')\n", "mpg_df.head(3)" ] }, { "cell_type": "markdown", "id": "included-vacation", "metadata": {}, "source": [ "#### 1. Default Tooltips" ] }, { "cell_type": "code", "execution_count": 4, "id": "hispanic-movement", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ggplot(mpg_df, aes(x=\"class\", y=\"hwy\")) + geom_boxplot()" ] }, { "cell_type": "markdown", "id": "trying-country", "metadata": {}, "source": [ "#### 2. `disable_splitting()`\n", "\n", "The function moves all side tooltips to the general tooltip. " ] }, { "cell_type": "code", "execution_count": 5, "id": "incident-province", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ggplot(mpg_df, aes(x=\"class\", y=\"hwy\")) + geom_boxplot(tooltips=layer_tooltips().disable_splitting())" ] }, { "cell_type": "markdown", "id": "collectible-figure", "metadata": {}, "source": [ "#### 3. `disable_splitting()` with Specified Tooltip Lines\n", "\n", "All side tooltips are hidden, the general tooltip gets the specified lines." ] }, { "cell_type": "code", "execution_count": 6, "id": "compliant-dylan", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ggplot(mpg_df, aes(x=\"class\", y=\"hwy\")) + geom_boxplot(tooltips=layer_tooltips()\n", " .line(\"@|^middle\")\n", " .disable_splitting())" ] } ], "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.8.17" } }, "nbformat": 4, "nbformat_minor": 5 }