{ "cells": [ { "cell_type": "markdown", "id": "bbf78031", "metadata": {}, "source": [ "# Lollipop Plot\n", "\n", "A lollipop plot displays each element of a dataset as a segment and a circle. It is usually combined with the `count` stat, and is especially useful when you have several bars of the same height." ] }, { "cell_type": "markdown", "id": "69de96f3", "metadata": {}, "source": [ "1. [Parameters `size`, `stroke` and `linewidth`](#stroke)\n", "\n", "2. [Parameter `fatten`](#fatten)\n", "\n", "3. [Horizontal Sticks](#direction)\n", "\n", "4. [Sloped Baseline](#slope)\n", "\n", "5. [Parameter `stat`](#stat)\n", "\n", "6. [Lollipops in Marginal Layer](#ggmarginal)\n", "\n", "7. [Lollipops and a Regression Line](#slope_and_intercept)\n" ] }, { "cell_type": "code", "execution_count": 1, "id": "4e5f30b9", "metadata": { "execution": { "iopub.execute_input": "2024-04-26T11:48:03.252144Z", "iopub.status.busy": "2024-04-26T11:48:03.252144Z", "iopub.status.idle": "2024-04-26T11:48:05.645840Z", "shell.execute_reply": "2024-04-26T11:48:05.645840Z" } }, "outputs": [], "source": [ "import random\n", "import pandas as pd\n", "from sklearn.linear_model import LinearRegression\n", "\n", "from lets_plot import *" ] }, { "cell_type": "code", "execution_count": 2, "id": "aca5e584", "metadata": { "execution": { "iopub.execute_input": "2024-04-26T11:48:05.645840Z", "iopub.status.busy": "2024-04-26T11:48:05.645840Z", "iopub.status.idle": "2024-04-26T11:48:05.661581Z", "shell.execute_reply": "2024-04-26T11:48:05.661581Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "LetsPlot.setup_html()" ] }, { "cell_type": "code", "execution_count": 3, "id": "1a13082d", "metadata": { "execution": { "iopub.execute_input": "2024-04-26T11:48:05.661581Z", "iopub.status.busy": "2024-04-26T11:48:05.661581Z", "iopub.status.idle": "2024-04-26T11:48:05.677206Z", "shell.execute_reply": "2024-04-26T11:48:05.677206Z" } }, "outputs": [], "source": [ "data = {\n", " 'x': [v - 15 for v in range(30)],\n", " 'y': [random.uniform(1, 5) for _ in range(30)],\n", " 'sugar': [v + 150 for v in range(30)]\n", "}" ] }, { "cell_type": "code", "execution_count": 4, "id": "fd78698e", "metadata": { "execution": { "iopub.execute_input": "2024-04-26T11:48:05.677206Z", "iopub.status.busy": "2024-04-26T11:48:05.677206Z", "iopub.status.idle": "2024-04-26T11:48:05.804022Z", "shell.execute_reply": "2024-04-26T11:48:05.804022Z" } }, "outputs": [ { "data": { "text/html": [ " \n", " " ], "text/plain": [ "\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", "