threshold in geom_histogram()¶The threshold parameter controls how the bin statistic is computed. When threshold=None (the default), all bins are retained.
When threshold=0 or other numeric value, bins with counts less than or equal to that threshold are dropped.
Dropping empty bins is particularly useful for faceted plots with free scales.
import pandas as pd
from lets_plot import *
LetsPlot.setup_html()
iris = pd.read_csv('https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/iris.csv')
p = ggplot(iris, aes(x='petal_length', fill='species')) + facet_wrap(facets='species', scales='free_x')
Despite scales='free_x', the x-axis still appears to be shared across the plot facets.
p + geom_histogram(alpha=.5)
p + geom_histogram(threshold=0, alpha=.5)