{ "cells": [ { "cell_type": "markdown", "id": "2ac0e74d", "metadata": {}, "source": [ "# Axis Position\n", "\n", "The `position` parameter in `scale_x_(), scale_y_()` functions controls position of the axis:\n", "\n", "- 'left', 'right' or 'both' for y-axis;\n", "- 'top', 'bottom' or 'both' for x-axis.\n" ] }, { "cell_type": "code", "execution_count": 1, "id": "8ab5b1ed", "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "\n", "from lets_plot import *" ] }, { "cell_type": "code", "execution_count": 2, "id": "b0b9825c", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "LetsPlot.setup_html()\n", "LetsPlot.set_theme(theme_grey())" ] }, { "cell_type": "code", "execution_count": 3, "id": "5e6d519e", "metadata": {}, "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", "
sepal_lengthsepal_widthpetal_lengthpetal_widthspecies
05.13.51.40.2setosa
14.93.01.40.2setosa
24.73.21.30.2setosa
\n", "
" ], "text/plain": [ " sepal_length sepal_width petal_length petal_width species\n", "0 5.1 3.5 1.4 0.2 setosa\n", "1 4.9 3.0 1.4 0.2 setosa\n", "2 4.7 3.2 1.3 0.2 setosa" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = pd.read_csv('https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/iris.csv')\n", "df.head(3)" ] }, { "cell_type": "markdown", "id": "b8877904", "metadata": {}, "source": [ "#### 1. Default Axis Position\n" ] }, { "cell_type": "code", "execution_count": 4, "id": "e0859183", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p = (ggplot(df) + geom_point(aes(\"sepal_width\", \"sepal_length\", color=\"species\"), size=5)\n", " + scale_color_brewer(palette=\"Set1\")\n", " )\n", "p" ] }, { "cell_type": "markdown", "id": "8e816608", "metadata": {}, "source": [ "#### 2. `position=\"right\"`" ] }, { "cell_type": "code", "execution_count": 5, "id": "0202aa5c", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p + scale_y_continuous(\"Sepal Length\", position=\"right\")" ] }, { "cell_type": "markdown", "id": "9e01a07b", "metadata": {}, "source": [ "#### 3. `position=\"top\"`" ] }, { "cell_type": "code", "execution_count": 6, "id": "4cc9ecd1", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p + scale_x_continuous(position=\"top\")" ] }, { "cell_type": "markdown", "id": "11909c79", "metadata": {}, "source": [ "#### 4. `position=\"both\"`" ] }, { "cell_type": "code", "execution_count": 7, "id": "b6dfc0a2", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(p\n", " + scale_x_continuous(\"Sepal Width\", position=\"both\")\n", " + scale_y_continuous(\"Sepal Length\", position=\"both\")\n", ")" ] }, { "cell_type": "markdown", "id": "346bad10", "metadata": {}, "source": [ "##### 4.1 Lets use equal units on the X-axis and on the Y-axis." ] }, { "cell_type": "code", "execution_count": 8, "id": "a360a62d", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(p\n", " + scale_x_continuous(\"Sepal Width\", position=\"both\")\n", " + scale_y_continuous(\"Sepal Length\", position=\"both\")\n", " + coord_fixed()\n", ")" ] } ], "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.8.15" } }, "nbformat": 4, "nbformat_minor": 5 }