{ "cells": [ { "cell_type": "markdown", "id": "4d37b3c0", "metadata": {}, "source": [ "# Axis Position\n", "\n", "The `position` parameter in `scaleX*(), scaleY*()` 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": "e235af3f", "metadata": { "execution": { "iopub.execute_input": "2024-08-23T10:52:42.748431Z", "iopub.status.busy": "2024-08-23T10:52:42.747156Z", "iopub.status.idle": "2024-08-23T10:52:45.430627Z", "shell.execute_reply": "2024-08-23T10:52:45.430340Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%useLatestDescriptors\n", "%use lets-plot\n", "%use dataframe" ] }, { "cell_type": "code", "execution_count": 2, "id": "2a5f04f2", "metadata": { "execution": { "iopub.execute_input": "2024-08-23T10:52:45.432465Z", "iopub.status.busy": "2024-08-23T10:52:45.432211Z", "iopub.status.idle": "2024-08-23T10:52:45.464565Z", "shell.execute_reply": "2024-08-23T10:52:45.464736Z" } }, "outputs": [ { "data": { "text/plain": [ "Lets-Plot Kotlin API v.4.8.0. Frontend: Notebook with dynamically loaded JS. Lets-Plot JS v.4.4.1." ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "LetsPlot.getInfo()" ] }, { "cell_type": "code", "execution_count": 3, "id": "d0ad53fd", "metadata": { "execution": { "iopub.execute_input": "2024-08-23T10:52:45.466248Z", "iopub.status.busy": "2024-08-23T10:52:45.466088Z", "iopub.status.idle": "2024-08-23T10:52:45.917857Z", "shell.execute_reply": "2024-08-23T10:52:45.917595Z" } }, "outputs": [ { "data": { "application/kotlindataframe+json": "{\"nrow\":3,\"ncol\":5,\"columns\":[\"sepal_length\",\"sepal_width\",\"petal_length\",\"petal_width\",\"species\"],\"kotlin_dataframe\":[{\"sepal_length\":5.1,\"sepal_width\":3.5,\"petal_length\":1.4,\"petal_width\":0.2,\"species\":\"setosa\"},{\"sepal_length\":4.9,\"sepal_width\":3.0,\"petal_length\":1.4,\"petal_width\":0.2,\"species\":\"setosa\"},{\"sepal_length\":4.7,\"sepal_width\":3.2,\"petal_length\":1.3,\"petal_width\":0.2,\"species\":\"setosa\"}]}", "text/html": [ " \n", " \n", " \n", " \n", " \n", "
\n", "\n", "

DataFrame: rowsCount = 3, columnsCount = 5

\n", "
sepal_lengthsepal_widthpetal_lengthpetal_widthspecies
5.1000003.5000001.4000000.200000setosa
4.9000003.0000001.4000000.200000setosa
4.7000003.2000001.3000000.200000setosa
\n", " \n", " \n", " " ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "val df = DataFrame.readCSV(\"https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/iris.csv\")\n", "df.head(3)" ] }, { "cell_type": "markdown", "id": "744364d5", "metadata": {}, "source": [ "#### 1. Default Axis Position" ] }, { "cell_type": "code", "execution_count": 4, "id": "37061a69", "metadata": { "execution": { "iopub.execute_input": "2024-08-23T10:52:45.920412Z", "iopub.status.busy": "2024-08-23T10:52:45.919750Z", "iopub.status.idle": "2024-08-23T10:52:46.071382Z", "shell.execute_reply": "2024-08-23T10:52:46.071119Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "val p = letsPlot(df.toMap()) + \n", " geomPoint(size=5) { x = \"sepal_width\"; y = \"sepal_length\"; color = \"species\" } +\n", " scaleColorBrewer(palette = \"Set1\") +\n", " themeGrey()\n", "p " ] }, { "cell_type": "markdown", "id": "a093bb47", "metadata": {}, "source": [ "#### 2. `position = \"right\"`" ] }, { "cell_type": "code", "execution_count": 5, "id": "d8528ed1", "metadata": { "execution": { "iopub.execute_input": "2024-08-23T10:52:46.073461Z", "iopub.status.busy": "2024-08-23T10:52:46.073049Z", "iopub.status.idle": "2024-08-23T10:52:46.125073Z", "shell.execute_reply": "2024-08-23T10:52:46.125248Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p + scaleYContinuous(\"Sepal Length\", position = \"right\")" ] }, { "cell_type": "markdown", "id": "e19d1327", "metadata": {}, "source": [ "#### 3. `position = \"top\"`" ] }, { "cell_type": "code", "execution_count": 6, "id": "93aee992", "metadata": { "execution": { "iopub.execute_input": "2024-08-23T10:52:46.126892Z", "iopub.status.busy": "2024-08-23T10:52:46.126626Z", "iopub.status.idle": "2024-08-23T10:52:46.169608Z", "shell.execute_reply": "2024-08-23T10:52:46.169714Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p + scaleXContinuous(position = \"top\")" ] }, { "cell_type": "markdown", "id": "91baa6d8", "metadata": {}, "source": [ "#### 4. `position = \"both\"`" ] }, { "cell_type": "code", "execution_count": 7, "id": "41bda5f8", "metadata": { "execution": { "iopub.execute_input": "2024-08-23T10:52:46.171161Z", "iopub.status.busy": "2024-08-23T10:52:46.170903Z", "iopub.status.idle": "2024-08-23T10:52:46.216568Z", "shell.execute_reply": "2024-08-23T10:52:46.216739Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p + scaleXContinuous(\"Sepal Width\", position=\"both\") + \n", " scaleYContinuous(\"Sepal Length\", position=\"both\")" ] }, { "cell_type": "markdown", "id": "bb17ef00", "metadata": {}, "source": [ "##### 4.1 Lets use equal units on the X-axis and on the Y-axis." ] }, { "cell_type": "code", "execution_count": 8, "id": "4f3ab3cc", "metadata": { "execution": { "iopub.execute_input": "2024-08-23T10:52:46.218245Z", "iopub.status.busy": "2024-08-23T10:52:46.218000Z", "iopub.status.idle": "2024-08-23T10:52:46.274899Z", "shell.execute_reply": "2024-08-23T10:52:46.274683Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p + scaleXContinuous(\"Sepal Width\", position = \"both\") + \n", " scaleYContinuous(\"Sepal Length\", position = \"both\") + \n", " coordFixed()" ] } ], "metadata": { "kernelspec": { "display_name": "Kotlin", "language": "kotlin", "name": "kotlin" }, "language_info": { "codemirror_mode": "text/x-kotlin", "file_extension": ".kt", "mimetype": "text/x-kotlin", "name": "kotlin", "nbconvert_exporter": "", "pygments_lexer": "kotlin", "version": "1.9.23" } }, "nbformat": 4, "nbformat_minor": 5 }