{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "9e03e303-0954-4928-9b99-556210d1f283", "metadata": {}, "outputs": [], "source": [ "from lets_plot import *" ] }, { "cell_type": "code", "execution_count": 2, "id": "b1c630b5-3639-4c42-85a2-f416ddd08908", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "LetsPlot.setup_html()" ] }, { "cell_type": "code", "execution_count": 3, "id": "d7b371ef-ecdb-467d-be4f-e5ad2c64d58c", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "def plot1(position=None):\n", " data = {'x': [0, 0], 'y': [0, 0], 'g': ['a', 'b']}\n", " return ggplot(data, aes('x', 'y', color='g')) + \\\n", " geom_point(position=position) + \\\n", " ggtitle(\"position={0}\".format(str(position).replace(\"\\n\", \"\")))\n", "\n", "gggrid([\n", " plot1(),\n", " plot1(\"dodge\"),\n", " plot1(position_dodge()),\n", " plot1(position_dodge(width=1.5)),\n", "], ncol=2)" ] }, { "cell_type": "code", "execution_count": 4, "id": "9e2c011a-e49a-4646-8129-0fb92f7547ba", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "def plot2(position=None):\n", " data = {\n", " 'x': ['a', 'a', 'a', 'a', 'b', 'b', 'b', 'b'],\n", " 'y': [0, 1, -1, 0, -1, 2, -2, 1],\n", " 'g': ['x', 'x', 'y', 'y', 'x', 'x', 'y', 'y']\n", " }\n", " return ggplot(data, aes('x', 'y', color='g')) + \\\n", " geom_boxplot(position=position) + \\\n", " ggtitle(\"position={0}\".format(str(position).replace(\"\\n\", \"\")))\n", "\n", "gggrid([\n", " plot2(),\n", " plot2(\"dodge\"),\n", " plot2(position_dodge()),\n", " plot2(position_dodge(width=1.5)),\n", " plot2(\"jitter\"),\n", " plot2(position_jitter()),\n", " plot2(position_jitter(width=2, height=10)),\n", "], ncol=2)" ] }, { "cell_type": "code", "execution_count": 5, "id": "7ae5c363-e82b-480a-ad45-97b74ba741c1", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "def plot3(*, width=None, height=None, position=None):\n", " data = {'x': [0] * 5000, 'y': [0] * 5000}\n", " return ggplot(data, aes('x', 'y')) + \\\n", " geom_jitter(width=width, height=height, position=position) + \\\n", " ggtitle(\"width={0}, height={1},\\nposition={2}\".format(width, height, str(position).replace(\"\\n\", \"\")))\n", "\n", "gggrid([\n", " plot3(),\n", " plot3(width=2, height=1),\n", " plot3(position=position_jitter(width=4, height=2)),\n", " plot3(width=2, height=1, position=position_jitter(width=4, height=2)),\n", " plot3(width=2, position=position_jitter(height=2)),\n", "], ncol=2)" ] }, { "cell_type": "code", "execution_count": 6, "id": "fd03093d-47db-4133-8014-a9b0a3b4b3fd", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "def plot4(stackgroups=None):\n", " data = {\n", " 'x': ['a', 'a', 'a', 'a', 'b', 'b', 'b', 'b'],\n", " 'y': [0, 1, -1, 0, -1, 2, -2, 1],\n", " 'g': ['x', 'x', 'y', 'y', 'x', 'x', 'y', 'y']\n", " }\n", " return ggplot(data, aes('x', 'y', fill='g')) + \\\n", " geom_ydotplot(stackgroups=stackgroups, dotsize=5, alpha=.5) + \\\n", " ggtitle(\"stackgroups={0}\".format(stackgroups))\n", "\n", "gggrid([\n", " plot4(False),\n", " plot4(True),\n", "])" ] }, { "cell_type": "code", "execution_count": 7, "id": "72bbb015-8d04-4d1c-a426-88d3a58108cc", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "def plot5(*, nudge_x=None, nudge_y=None, position=None):\n", " data = {'x': [0, 0], 'y': [0, 0], 'g': ['a', 'b']}\n", " return ggplot(data, aes('x', 'y', color='g')) + \\\n", " geom_point(size=40, alpha=.2) + \\\n", " geom_text(aes(label='g'), nudge_x=nudge_x, nudge_y=nudge_y, position=position, \\\n", " size=20, show_legend=False) + \\\n", " ggtitle(\"nudge_x={0}, nudge_y={1},\\nposition={2}\".format(nudge_x, nudge_y, str(position).replace(\"\\n\", \"\")))\n", "\n", "gggrid([\n", " plot5(),\n", " plot5(nudge_x=.2),\n", " plot5(nudge_x=.2, position='identity'),\n", " plot5(nudge_x=.2, position=position_nudge(x=.4)),\n", " plot5(nudge_x=.2, position=position_nudge(y=.2)),\n", " plot5(position='dodge'),\n", " plot5(nudge_x=.2, position='dodge'),\n", " plot5(nudge_y=.2, position='dodge'),\n", "], ncol=2)" ] } ], "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.15" } }, "nbformat": 4, "nbformat_minor": 5 }