{ "cells": [ { "cell_type": "markdown", "id": "6dcc53b5-1d5e-4ada-a3f9-da878c3e1eda", "metadata": {}, "source": [ "# Parameter `threshold` in `geomHistogram()`\n", "\n", "The `threshold` parameter controls how the `bin` statistic is computed. When `threshold=null` (the default), all bins are retained.\n", "\n", "When `threshold=0` or other numeric value, bins with counts less than or equal to that threshold are dropped.\n", "\n", "Dropping empty bins is particularly useful for faceted plots with free scales." ] }, { "cell_type": "code", "execution_count": 1, "id": "13dd0235-9b1b-4218-9185-ee2785ec1465", "metadata": { "execution": { "iopub.execute_input": "2024-11-01T20:36:04.759945Z", "iopub.status.busy": "2024-11-01T20:36:04.757789Z", "iopub.status.idle": "2024-11-01T20:36:07.705804Z", "shell.execute_reply": "2024-11-01T20:36:07.705617Z" } }, "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" } ], "source": [ "%useLatestDescriptors\n", "%use dataframe\n", "%use lets-plot" ] }, { "cell_type": "code", "execution_count": 2, "id": "4c6dc9f7-7ca0-4b98-80aa-cd516a6a104d", "metadata": { "execution": { "iopub.execute_input": "2024-11-01T20:36:07.707094Z", "iopub.status.busy": "2024-11-01T20:36:07.706842Z", "iopub.status.idle": "2024-11-01T20:36:07.742991Z", "shell.execute_reply": "2024-11-01T20:36:07.742544Z" } }, "outputs": [ { "data": { "text/plain": [ "Lets-Plot Kotlin API v.4.9.0. Frontend: Notebook with dynamically loaded JS. Lets-Plot JS v.4.5.1." ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "LetsPlot.getInfo()" ] }, { "cell_type": "code", "execution_count": 3, "id": "d3ca1f59-764d-4696-ba7f-a1c1cc3a6601", "metadata": { "execution": { "iopub.execute_input": "2024-11-01T20:36:07.744499Z", "iopub.status.busy": "2024-11-01T20:36:07.744214Z", "iopub.status.idle": "2024-11-01T20:36:08.096645Z", "shell.execute_reply": "2024-11-01T20:36:08.096402Z" } }, "outputs": [], "source": [ "val iris = DataFrame.readCSV(\"https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/iris.csv\")\n", "\n", "val p = letsPlot(iris.toMap()) { \n", " x = \"petal_length\"\n", " fill = \"species\" \n", "} + facetWrap(\n", " facets = \"species\", \n", " scales = \"free_x\"\n", ")" ] }, { "cell_type": "markdown", "id": "f40e5f34-2e4a-4963-a7ab-af7c04147701", "metadata": {}, "source": [ "#### 1. Default Faceted Histogram with `free` X-axis\n", "\n", "Despite `scales='free_x'`, the x-axis still appears to be shared across the plot facets." ] }, { "cell_type": "code", "execution_count": 4, "id": "7dc1c7c4-225b-4146-81e8-c2e42b51f8e8", "metadata": { "execution": { "iopub.execute_input": "2024-11-01T20:36:08.098227Z", "iopub.status.busy": "2024-11-01T20:36:08.097961Z", "iopub.status.idle": "2024-11-01T20:36:08.253245Z", "shell.execute_reply": "2024-11-01T20:36:08.253136Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p + geomHistogram()" ] }, { "cell_type": "markdown", "id": "029e1bf6-4bef-4fb5-ad26-1f3afc15c18c", "metadata": {}, "source": [ "#### 2. With a Threshold\n" ] }, { "cell_type": "code", "execution_count": 5, "id": "8a9c6467-e3a2-4284-9847-77d591507d91", "metadata": { "execution": { "iopub.execute_input": "2024-11-01T20:36:08.254547Z", "iopub.status.busy": "2024-11-01T20:36:08.254394Z", "iopub.status.idle": "2024-11-01T20:36:08.302928Z", "shell.execute_reply": "2024-11-01T20:36:08.302805Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p + geomHistogram(threshold = 0)" ] } ], "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 }