{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "execution": { "iopub.execute_input": "2024-04-17T07:34:53.541409Z", "iopub.status.busy": "2024-04-17T07:34:53.541308Z", "iopub.status.idle": "2024-04-17T07:34:53.865151Z", "shell.execute_reply": "2024-04-17T07:34:53.864864Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import numpy as np\n", "\n", "from lets_plot import *\n", "LetsPlot.setup_html()" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "execution": { "iopub.execute_input": "2024-04-17T07:34:53.878940Z", "iopub.status.busy": "2024-04-17T07:34:53.878785Z", "iopub.status.idle": "2024-04-17T07:34:53.880670Z", "shell.execute_reply": "2024-04-17T07:34:53.880327Z" } }, "outputs": [], "source": [ "np.random.seed(42)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "execution": { "iopub.execute_input": "2024-04-17T07:34:53.881864Z", "iopub.status.busy": "2024-04-17T07:34:53.881708Z", "iopub.status.idle": "2024-04-17T07:34:53.883623Z", "shell.execute_reply": "2024-04-17T07:34:53.883438Z" } }, "outputs": [], "source": [ "x_a = np.random.normal(-0.5, 1, 100)\n", "y_a = np.random.normal(0, 1, 100)\n", "cat_a = ['A' for x in range(100)]\n", "\n", "x_b = np.random.normal(0.5, 1, 100)\n", "y_b = np.random.normal(0, 1, 100)\n", "cat_b = ['B' for x in range(100)]" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "execution": { "iopub.execute_input": "2024-04-17T07:34:53.884745Z", "iopub.status.busy": "2024-04-17T07:34:53.884559Z", "iopub.status.idle": "2024-04-17T07:34:53.886221Z", "shell.execute_reply": "2024-04-17T07:34:53.886039Z" } }, "outputs": [], "source": [ "data = {}\n", "data['x'] = np.concatenate((x_a, x_b))\n", "data['y'] = np.concatenate((y_a, y_b))\n", "data['cat'] = np.concatenate((cat_a, cat_b))" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "execution": { "iopub.execute_input": "2024-04-17T07:34:53.887081Z", "iopub.status.busy": "2024-04-17T07:34:53.887005Z", "iopub.status.idle": "2024-04-17T07:34:53.920060Z", "shell.execute_reply": "2024-04-17T07:34:53.919855Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p = ggplot(data, aes('x', fill='cat'))\n", "p + geom_point(aes(y='y', color='cat'), size=3, alpha=0.8) + \\\n", " ggtitle('Scatter plot')" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "execution": { "iopub.execute_input": "2024-04-17T07:34:53.921243Z", "iopub.status.busy": "2024-04-17T07:34:53.921155Z", "iopub.status.idle": "2024-04-17T07:34:53.924050Z", "shell.execute_reply": "2024-04-17T07:34:53.923872Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p + geom_histogram() + \\\n", " ggtitle('Default histogram')" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "execution": { "iopub.execute_input": "2024-04-17T07:34:53.925130Z", "iopub.status.busy": "2024-04-17T07:34:53.924958Z", "iopub.status.idle": "2024-04-17T07:34:53.927721Z", "shell.execute_reply": "2024-04-17T07:34:53.927548Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p + geom_histogram(position='dodge') + \\\n", " ggtitle('Interleaved histogram')" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "execution": { "iopub.execute_input": "2024-04-17T07:34:53.928630Z", "iopub.status.busy": "2024-04-17T07:34:53.928553Z", "iopub.status.idle": "2024-04-17T07:34:53.931326Z", "shell.execute_reply": "2024-04-17T07:34:53.931158Z" }, "scrolled": false }, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p + geom_histogram(alpha=0.5, position='identity') + \\\n", " ggtitle('Overlaid semi transparent histogram')" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "execution": { "iopub.execute_input": "2024-04-17T07:34:53.932213Z", "iopub.status.busy": "2024-04-17T07:34:53.932133Z", "iopub.status.idle": "2024-04-17T07:34:53.935038Z", "shell.execute_reply": "2024-04-17T07:34:53.934867Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p + geom_histogram(bins=10, color='white', size=0.5) + \\\n", " ggtitle('Histogram with bins=10')" ] } ], "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": 1 }