{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "execution": { "iopub.execute_input": "2024-04-26T11:56:36.233138Z", "iopub.status.busy": "2024-04-26T11:56:36.233138Z", "iopub.status.idle": "2024-04-26T11:56:37.199308Z", "shell.execute_reply": "2024-04-26T11:56:37.199308Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import pandas as pd\n", "\n", "from lets_plot import *\n", "LetsPlot.setup_html()" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "execution": { "iopub.execute_input": "2024-04-26T11:56:37.215066Z", "iopub.status.busy": "2024-04-26T11:56:37.215066Z", "iopub.status.idle": "2024-04-26T11:56:37.246373Z", "shell.execute_reply": "2024-04-26T11:56:37.246373Z" } }, "outputs": [], "source": [ "df = {'cond': ['A', 'A', 'B', 'B', 'C', 'C'], \\\n", " 'x': [2, 3, 2, 3, 2, 3], \\\n", " 'y': [1.0, 1.5, 2.0, 1.0, 1.6, 1.8]}" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "execution": { "iopub.execute_input": "2024-04-26T11:56:37.246373Z", "iopub.status.busy": "2024-04-26T11:56:37.246373Z", "iopub.status.idle": "2024-04-26T11:56:37.356963Z", "shell.execute_reply": "2024-04-26T11:56:37.356963Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Let's plot default lines and points\n", "ggplot(df) + geom_line(aes(x='x', y='y', group='cond')) + \\\n", " geom_point(aes(x='x', y='y'))" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "execution": { "iopub.execute_input": "2024-04-26T11:56:37.356963Z", "iopub.status.busy": "2024-04-26T11:56:37.356963Z", "iopub.status.idle": "2024-04-26T11:56:37.373972Z", "shell.execute_reply": "2024-04-26T11:56:37.372675Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Let's set dotted thicker line and hollow large squares\n", "ggplot(df) + geom_line(aes(x='x', y='y', group='cond'), linetype='dotted', size = 1.5) + \\\n", " geom_point(aes(x='x', y='y'), shape = 0, size = 4)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "execution": { "iopub.execute_input": "2024-04-26T11:56:37.375943Z", "iopub.status.busy": "2024-04-26T11:56:37.375943Z", "iopub.status.idle": "2024-04-26T11:56:37.388657Z", "shell.execute_reply": "2024-04-26T11:56:37.388657Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# We can make line type and shape of points depend on variable\n", "ggplot(df) + geom_line(aes(x='x', y='y', group='cond', linetype='cond')) + \\\n", " geom_point(aes(x='x', y='y', shape='cond'), size=4)\n" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "execution": { "iopub.execute_input": "2024-04-26T11:56:37.388657Z", "iopub.status.busy": "2024-04-26T11:56:37.388657Z", "iopub.status.idle": "2024-04-26T11:56:37.404530Z", "shell.execute_reply": "2024-04-26T11:56:37.404530Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# The same but with hollow shapes\n", "ggplot(df, aes(x='x', y='y', group='cond')) + \\\n", " geom_line(aes(linetype='cond')) + \\\n", " geom_point(aes(shape='cond'), size=4) + scale_shape(solid=False)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "execution": { "iopub.execute_input": "2024-04-26T11:56:37.404530Z", "iopub.status.busy": "2024-04-26T11:56:37.404530Z", "iopub.status.idle": "2024-04-26T11:56:37.420376Z", "shell.execute_reply": "2024-04-26T11:56:37.420376Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Let's manually change the specific linetypes and shapes that are used\n", "ggplot(df) + geom_line(aes(x='x', y='y', group='cond', linetype='cond')) + \\\n", " geom_point(aes(x='x', y='y', shape='cond'), size=4) + \\\n", " scale_linetype_manual(values=('dotdash', 'dotted', 'dashed')) + \\\n", " scale_shape_manual(values=(6, 7, 8))" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "execution": { "iopub.execute_input": "2024-04-26T11:56:37.420376Z", "iopub.status.busy": "2024-04-26T11:56:37.420376Z", "iopub.status.idle": "2024-04-26T11:56:37.436923Z", "shell.execute_reply": "2024-04-26T11:56:37.435949Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Let's set gray lines and shapes with green fill\n", "ggplot(df, aes(x='x', y='y', group='cond')) + \\\n", " geom_line(aes(linetype='cond'), size=1.5, color='gray') + \\\n", " geom_point(aes(shape='cond'), fill='dark_green', color='gray', size=6) + \\\n", " scale_shape_manual(values=(21,22,24)) # Shapes: Filled circle, square, triangle" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "execution": { "iopub.execute_input": "2024-04-26T11:56:37.436923Z", "iopub.status.busy": "2024-04-26T11:56:37.436923Z", "iopub.status.idle": "2024-04-26T11:56:37.452099Z", "shell.execute_reply": "2024-04-26T11:56:37.452099Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# We can also add alpha channel(transparency)\n", "ggplot(df, aes(x='x', y='y', group='cond')) + \\\n", " geom_line(aes(linetype='cond'), size = 1.5, color='gray', alpha=.5) + \\\n", " geom_point(aes(shape='cond'), fill='dark_green', color='gray', size=6, alpha=.7) + \\\n", " scale_shape_manual(values=(21,22,24))" ] } ], "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 }