{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "execution": { "iopub.execute_input": "2024-04-17T07:26:22.521197Z", "iopub.status.busy": "2024-04-17T07:26:22.521112Z", "iopub.status.idle": "2024-04-17T07:26:22.840556Z", "shell.execute_reply": "2024-04-17T07:26:22.840325Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import numpy as np\n", "import pandas as pd\n", "\n", "from lets_plot import *\n", "from lets_plot.mapping import as_discrete\n", "\n", "LetsPlot.setup_html()" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "execution": { "iopub.execute_input": "2024-04-17T07:26:22.853967Z", "iopub.status.busy": "2024-04-17T07:26:22.853837Z", "iopub.status.idle": "2024-04-17T07:26:23.001012Z", "shell.execute_reply": "2024-04-17T07:26:23.000611Z" } }, "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": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mpg = pd.read_csv(\"https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/mpg.csv\")\n", "mpg.head(3)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "execution": { "iopub.execute_input": "2024-04-17T07:26:23.002173Z", "iopub.status.busy": "2024-04-17T07:26:23.002085Z", "iopub.status.idle": "2024-04-17T07:26:23.004115Z", "shell.execute_reply": "2024-04-17T07:26:23.003921Z" } }, "outputs": [], "source": [ "p = ggplot(mpg) + theme(axis_title_x='blank')" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "execution": { "iopub.execute_input": "2024-04-17T07:26:23.005207Z", "iopub.status.busy": "2024-04-17T07:26:23.005126Z", "iopub.status.idle": "2024-04-17T07:26:23.038340Z", "shell.execute_reply": "2024-04-17T07:26:23.038149Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "box_plot = (p + \n", " geom_boxplot(aes(as_discrete('class',order=1, order_by='..middle..'), 'hwy'),\n", " color=\"#579673\", fill=\"#9AC0B3\", size=1.5) +\n", " ggsize(700, 300))\n", "box_plot + ggtitle(\"Default\")" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "execution": { "iopub.execute_input": "2024-04-17T07:26:23.039417Z", "iopub.status.busy": "2024-04-17T07:26:23.039342Z", "iopub.status.idle": "2024-04-17T07:26:23.043945Z", "shell.execute_reply": "2024-04-17T07:26:23.043771Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "box_plot + ggtitle(\"Flipped\") + coord_flip()" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "execution": { "iopub.execute_input": "2024-04-17T07:26:23.045081Z", "iopub.status.busy": "2024-04-17T07:26:23.044916Z", "iopub.status.idle": "2024-04-17T07:26:23.049710Z", "shell.execute_reply": "2024-04-17T07:26:23.049539Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bar_plot = (p + \n", " geom_bar(aes(as_discrete('manufacturer',order_by='..count..'), fill='class', color='class'),\n", " size=1.5, alpha=0.7, width=0.7) +\n", " ggsize(800, 300))\n", "bar_plot + ggtitle(\"Default\")" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "execution": { "iopub.execute_input": "2024-04-17T07:26:23.050630Z", "iopub.status.busy": "2024-04-17T07:26:23.050486Z", "iopub.status.idle": "2024-04-17T07:26:23.054587Z", "shell.execute_reply": "2024-04-17T07:26:23.054414Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bar_plot + ggtitle(\"Flipped\") + coord_flip()" ] } ], "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.10.13" } }, "nbformat": 4, "nbformat_minor": 4 }