{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "execution": { "iopub.execute_input": "2024-04-26T11:51:16.935687Z", "iopub.status.busy": "2024-04-26T11:51:16.935687Z", "iopub.status.idle": "2024-04-26T11:51:17.896883Z", "shell.execute_reply": "2024-04-26T11:51:17.896883Z" } }, "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-26T11:51:17.928775Z", "iopub.status.busy": "2024-04-26T11:51:17.928775Z", "iopub.status.idle": "2024-04-26T11:51:17.945454Z", "shell.execute_reply": "2024-04-26T11:51:17.944600Z" } }, "outputs": [], "source": [ "np.random.seed(42)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "execution": { "iopub.execute_input": "2024-04-26T11:51:17.945454Z", "iopub.status.busy": "2024-04-26T11:51:17.945454Z", "iopub.status.idle": "2024-04-26T11:51:17.961336Z", "shell.execute_reply": "2024-04-26T11:51:17.960602Z" } }, "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-26T11:51:17.961336Z", "iopub.status.busy": "2024-04-26T11:51:17.961336Z", "iopub.status.idle": "2024-04-26T11:51:17.976565Z", "shell.execute_reply": "2024-04-26T11:51:17.976565Z" } }, "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-26T11:51:17.976565Z", "iopub.status.busy": "2024-04-26T11:51:17.976565Z", "iopub.status.idle": "2024-04-26T11:51:18.102431Z", "shell.execute_reply": "2024-04-26T11:51:18.102431Z" } }, "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-26T11:51:18.102431Z", "iopub.status.busy": "2024-04-26T11:51:18.102431Z", "iopub.status.idle": "2024-04-26T11:51:18.118251Z", "shell.execute_reply": "2024-04-26T11:51:18.118251Z" } }, "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-26T11:51:18.120802Z", "iopub.status.busy": "2024-04-26T11:51:18.120802Z", "iopub.status.idle": "2024-04-26T11:51:18.134422Z", "shell.execute_reply": "2024-04-26T11:51:18.134422Z" } }, "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-26T11:51:18.134422Z", "iopub.status.busy": "2024-04-26T11:51:18.134422Z", "iopub.status.idle": "2024-04-26T11:51:18.150193Z", "shell.execute_reply": "2024-04-26T11:51:18.150193Z" }, "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-26T11:51:18.150193Z", "iopub.status.busy": "2024-04-26T11:51:18.150193Z", "iopub.status.idle": "2024-04-26T11:51:18.165828Z", "shell.execute_reply": "2024-04-26T11:51:18.165828Z" } }, "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 }