{ "cells": [ { "cell_type": "markdown", "id": "2476ee0c-4cfe-4a75-934d-ba2edb2fd775", "metadata": {}, "source": [ "# Parameter `threshold` in `geom_histogram()`\n", "\n", "\n", "The `threshold` parameter controls how the `bin` statistic is computed. When `threshold=None` (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": "1f9cf7f9-dc56-4310-be9f-d4ec2761e05b", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import pandas as pd\n", "from lets_plot import *\n", "\n", "LetsPlot.setup_html()" ] }, { "cell_type": "code", "execution_count": 2, "id": "38decd07-e22d-4ee0-a924-9b16859b5303", "metadata": {}, "outputs": [], "source": [ "iris = pd.read_csv('https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/iris.csv')\n", "\n", "p = ggplot(iris, aes(x='petal_length', fill='species')) + facet_wrap(facets='species', scales='free_x')" ] }, { "cell_type": "markdown", "id": "5eaca38f-a2c4-45c5-8057-56ecfb336bc9", "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": 3, "id": "ea3f1e11-3bf3-49ac-9712-e9dca7461350", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p + geom_histogram(alpha=.5)" ] }, { "cell_type": "markdown", "id": "4f324322-6e3d-4de6-a93a-5871e7c665a2", "metadata": {}, "source": [ "#### 2. With a Threshold" ] }, { "cell_type": "code", "execution_count": 4, "id": "5985d9ff-7a14-45ca-bc9c-6a1e2f83e75f", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p + geom_histogram(threshold=0, alpha=.5)" ] } ], "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.19" } }, "nbformat": 4, "nbformat_minor": 5 }