{ "cells": [ { "cell_type": "markdown", "id": "667912ba", "metadata": {}, "source": [ "# Limiting Labels Length for Axis and Legends\n", "\n", "Use the `lablim` parameter in `scaleXxx()` functions to specify the maximum length (number of characters) of labels for correspondent axis or legend.\n", "\n", "Labels exceeding the specified maximum lenfth will be trimmed." ] }, { "cell_type": "code", "execution_count": 1, "id": "71955ca7", "metadata": {}, "outputs": [ { "data": { "text/html": [ " <div id=\"K6g7Jc\"></div>\n", " <script type=\"text/javascript\" data-lets-plot-script=\"library\">\n", " if(!window.letsPlotCallQueue) {\n", " window.letsPlotCallQueue = [];\n", " }; \n", " window.letsPlotCall = function(f) {\n", " window.letsPlotCallQueue.push(f);\n", " };\n", " (function() {\n", " var script = document.createElement(\"script\");\n", " script.type = \"text/javascript\";\n", " script.src = \"https://cdn.jsdelivr.net/gh/JetBrains/lets-plot@v4.2.0/js-package/distr/lets-plot.min.js\";\n", " script.onload = function() {\n", " window.letsPlotCall = function(f) {f();};\n", " window.letsPlotCallQueue.forEach(function(f) {f();});\n", " window.letsPlotCallQueue = [];\n", " \n", " \n", " };\n", " script.onerror = function(event) {\n", " window.letsPlotCall = function(f) {};\n", " window.letsPlotCallQueue = [];\n", " var div = document.createElement(\"div\");\n", " div.style.color = 'darkred';\n", " div.textContent = 'Error loading Lets-Plot JS';\n", " document.getElementById(\"K6g7Jc\").appendChild(div);\n", " };\n", " var e = document.getElementById(\"K6g7Jc\");\n", " e.appendChild(script);\n", " })();\n", " </script>" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%useLatestDescriptors\n", "%use lets-plot" ] }, { "cell_type": "code", "execution_count": 2, "id": "37bf065c", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Lets-Plot Kotlin API v.4.6.0. Frontend: Notebook with dynamically loaded JS. Lets-Plot JS v.4.2.0." ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "LetsPlot.getInfo()" ] }, { "cell_type": "markdown", "id": "af123880", "metadata": {}, "source": [ "#### 1. Long Labels without Trimming" ] }, { "cell_type": "code", "execution_count": 3, "id": "74d9efb4", "metadata": {}, "outputs": [ { "data": { "text/html": [ " <div id=\"MJ5mTj\"></div>\n", " <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n", " (function() {\n", " var plotSpec={\n", "\"mapping\":{\n", "\"x\":\"x\",\n", "\"color\":\"x\"\n", "},\n", "\"data\":{\n", "\"x\":[\"A picture is worth a thousand words\",\"Make a long story short\"]\n", "},\n", "\"kind\":\"plot\",\n", "\"scales\":[],\n", "\"layers\":[{\n", "\"mapping\":{\n", "},\n", "\"stat\":\"identity\",\n", "\"size\":7.0,\n", "\"position\":\"identity\",\n", "\"geom\":\"point\",\n", "\"data\":{\n", "}\n", "}]\n", "};\n", " var plotContainer = document.getElementById(\"MJ5mTj\");\n", " window.letsPlotCall(function() {{\n", " LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n", " }});\n", " })(); \n", " </script>" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "val data = mapOf(\n", " \"x\" to listOf(\"A picture is worth a thousand words\", \"Make a long story short\")\n", ")\n", "\n", "val p = letsPlot(data) { x = \"x\"; color = \"x\" } + geomPoint(size = 7)\n", "p" ] }, { "cell_type": "markdown", "id": "a71965ae", "metadata": {}, "source": [ "#### 2. Use `lablim` Parameter to Trim X-Axis Labels" ] }, { "cell_type": "code", "execution_count": 4, "id": "4fb52193", "metadata": {}, "outputs": [ { "data": { "text/html": [ " <div id=\"efSiwd\"></div>\n", " <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n", " (function() {\n", " var plotSpec={\n", "\"mapping\":{\n", "\"x\":\"x\",\n", "\"color\":\"x\"\n", "},\n", "\"data\":{\n", "\"x\":[\"A picture is worth a thousand words\",\"Make a long story short\"]\n", "},\n", "\"kind\":\"plot\",\n", "\"scales\":[{\n", "\"aesthetic\":\"x\",\n", "\"discrete\":true,\n", "\"lablim\":10\n", "}],\n", "\"layers\":[{\n", "\"mapping\":{\n", "},\n", "\"stat\":\"identity\",\n", "\"size\":7.0,\n", "\"position\":\"identity\",\n", "\"geom\":\"point\",\n", "\"data\":{\n", "}\n", "}]\n", "};\n", " var plotContainer = document.getElementById(\"efSiwd\");\n", " window.letsPlotCall(function() {{\n", " LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n", " }});\n", " })(); \n", " </script>" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p + scaleXDiscrete(lablim = 10)" ] } ], "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.8.20" } }, "nbformat": 4, "nbformat_minor": 5 }