{ "cells": [ { "cell_type": "markdown", "id": "73c458f4-8b2c-49e1-a7f4-f86764b65805", "metadata": {}, "source": [ "# Customizing Tick Marks in Colorbars\n", "\n", "Two new parameters in the `theme()` function, `legendTicks` and `legendTicksLength`, provide fine-grained control over colorbar tick marks." ] }, { "cell_type": "code", "execution_count": 1, "id": "24dd56b0-a4e9-4f06-838e-037b58e9015a", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ " " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ " \n", " " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%useLatestDescriptors\n", "%use dataframe\n", "%use lets-plot" ] }, { "cell_type": "code", "execution_count": 2, "id": "a92fb036-116f-4456-95c7-9bd506698ade", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Lets-Plot Kotlin API v.4.10.0. Frontend: Notebook with dynamically loaded JS. Lets-Plot JS v.4.6.1." ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "LetsPlot.getInfo()" ] }, { "cell_type": "code", "execution_count": 3, "id": "e0898429-1171-428c-97e7-bffc74d99b3c", "metadata": {}, "outputs": [ { "data": { "text/html": [ " \n", " " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/plot+json": { "apply_color_scheme": true, "output": { "data": { "time": [ "Lunch", "Lunch", "Dinner", "Dinner", "Dinner" ] }, "data_meta": { "series_annotations": [ { "column": "time", "type": "str" } ] }, "ggsize": { "height": 200, "width": 400 }, "kind": "plot", "layers": [ { "geom": "bar", "mapping": { "fill": "..count..", "x": "time" }, "position": "stack", "stat": "count" } ], "mapping": {}, "scales": [ { "aesthetic": "fill", "scale_mapper_kind": "color_grey" } ], "theme": { "axis": { "blank": true }, "line": { "blank": true }, "name": "classic" } }, "output_type": "lets_plot_spec", "swing_enabled": true }, "text/html": [ " \n", " \n", " " ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "val data = mapOf(\"time\" to listOf(\"Lunch\", \"Lunch\", \"Dinner\", \"Dinner\", \"Dinner\"))\n", "\n", "val p = letsPlot(data) + \n", " geomBar{x = \"time\"; fill = \"..count..\"} + \n", " scaleFillGrey() + \n", " themeVoid() + \n", " ggsize(400, 200)\n", "\n", "p" ] }, { "cell_type": "code", "execution_count": 4, "id": "49cfe840-7545-4d7b-8310-6eb7f6ca6acd", "metadata": {}, "outputs": [ { "data": { "application/plot+json": { "apply_color_scheme": true, "output": { "figures": [ { "data": { "time": [ "Lunch", "Lunch", "Dinner", "Dinner", "Dinner" ] }, "data_meta": { "series_annotations": [ { "column": "time", "type": "str" } ] }, "ggsize": { "height": 200, "width": 400 }, "ggtitle": { "text": "Long Ticks" }, "kind": "plot", "layers": [ { "geom": "bar", "mapping": { "fill": "..count..", "x": "time" }, "position": "stack", "stat": "count" } ], "mapping": {}, "scales": [ { "aesthetic": "fill", "scale_mapper_kind": "color_grey" } ], "theme": { "axis": { "blank": true }, "legend_ticks_length": 10, "line": { "blank": true }, "name": "classic" } }, { "data": { "time": [ "Lunch", "Lunch", "Dinner", "Dinner", "Dinner" ] }, "data_meta": { "series_annotations": [ { "column": "time", "type": "str" } ] }, "ggsize": { "height": 200, "width": 400 }, "ggtitle": { "text": "Thick Ticks" }, "kind": "plot", "layers": [ { "geom": "bar", "mapping": { "fill": "..count..", "x": "time" }, "position": "stack", "stat": "count" } ], "mapping": {}, "scales": [ { "aesthetic": "fill", "scale_mapper_kind": "color_grey" } ], "theme": { "axis": { "blank": true }, "legend_ticks": { "blank": false, "size": 4 }, "line": { "blank": true }, "name": "classic" } }, { "data": { "time": [ "Lunch", "Lunch", "Dinner", "Dinner", "Dinner" ] }, "data_meta": { "series_annotations": [ { "column": "time", "type": "str" } ] }, "ggsize": { "height": 200, "width": 400 }, "ggtitle": { "text": "Thick Red Ticks" }, "kind": "plot", "layers": [ { "geom": "bar", "mapping": { "fill": "..count..", "x": "time" }, "position": "stack", "stat": "count" } ], "mapping": {}, "scales": [ { "aesthetic": "fill", "scale_mapper_kind": "color_grey" } ], "theme": { "axis": { "blank": true }, "legend_ticks": { "blank": false, "color": "red", "size": 4 }, "line": { "blank": true }, "name": "classic" } }, { "data": { "time": [ "Lunch", "Lunch", "Dinner", "Dinner", "Dinner" ] }, "data_meta": { "series_annotations": [ { "column": "time", "type": "str" } ] }, "ggsize": { "height": 200, "width": 400 }, "ggtitle": { "text": "Hidden Ticks" }, "kind": "plot", "layers": [ { "geom": "bar", "mapping": { "fill": "..count..", "x": "time" }, "position": "stack", "stat": "count" } ], "mapping": {}, "scales": [ { "aesthetic": "fill", "scale_mapper_kind": "color_grey" } ], "theme": { "axis": { "blank": true }, "legend_ticks": "blank", "line": { "blank": true }, "name": "classic" } } ], "ggsize": { "height": 200, "width": 800 }, "kind": "subplots", "layout": { "align": false, "fit": true, "name": "grid", "ncol": 4, "nrow": 1 } }, "output_type": "lets_plot_spec", "swing_enabled": true }, "text/html": [ " \n", " \n", " " ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "val longTicks = theme(legendTicksLength = 10) + ggtitle(\"Long Ticks\")\n", "val thickTicks = theme(legendTicks = elementLine(size = 4)) + ggtitle(\"Thick Ticks\")\n", "val thickRedTicks = theme(legendTicks = elementLine(size = 4, color = \"red\")) + ggtitle(\"Thick Red Ticks\")\n", "val hiddenTicks = theme(legendTicks = \"blank\") + ggtitle(\"Hidden Ticks\")\n", "\n", "gggrid(\n", " listOf(\n", " p + longTicks,\n", " p + thickTicks,\n", " p + thickRedTicks,\n", " p + hiddenTicks\n", " )\n", ") + ggsize(800, 200)" ] } ], "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 }