{ "cells": [ { "cell_type": "markdown", "id": "d13bb6d9-afd1-4f5d-90ed-83892a0ed8d2", "metadata": {}, "source": [ "# Limiting Labels Length for Axis and Legends\n", "\n", "Use the `lablim` parameter in `scale_xxx()` 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.\n" ] }, { "cell_type": "code", "execution_count": 1, "id": "96bdba02-7084-4a95-a363-bfaf2fdc00f6", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from lets_plot import *\n", "LetsPlot.setup_html()" ] }, { "cell_type": "markdown", "id": "40f63905-9c3f-4593-9795-b8667d1daf91", "metadata": {}, "source": [ "#### 1. Long Labels without Trimming" ] }, { "cell_type": "code", "execution_count": 2, "id": "89f7671f-5e1f-4830-b5f8-dee8e5142c4b", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data = {\n", " 'x': ['A picture is worth a thousand words', 'Make a long story short']\n", "}\n", "\n", "p = ggplot(data, aes(x='x', color='x')) + geom_point(size=7)\n", "p" ] }, { "cell_type": "markdown", "id": "cf8daa5e-0887-4353-a18f-129b66916de9", "metadata": {}, "source": [ "#### 2. Use `lablim` Parameter to Trim X-Axis Labels" ] }, { "cell_type": "code", "execution_count": 3, "id": "1235d88c-0ca4-424f-93d6-54e8d36086b2", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p + scale_x_discrete(lablim=10)" ] } ], "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.18" } }, "nbformat": 4, "nbformat_minor": 5 }