Parameter 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.

In [1]:
import pandas as pd
from lets_plot import *

LetsPlot.setup_html()
In [2]:
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')

1. Default Faceted Histogram with Free X-axis

Despite scales='free_x', the x-axis still appears to be shared across the plot facets.

In [3]:
p + geom_histogram(alpha=.5)
Out[3]:

2. With a Threshold

In [4]:
p + geom_histogram(threshold=0, alpha=.5)
Out[4]: