You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using histogram binning (ridgeplot(samples=..., nbins=...)), the bins are always nbins equal-width bins spanning [min(samples), max(samples)] (numpy's default). For discrete/count data this means bars are generally not aligned with the sample values. For example, for samples=[[0, 1, 2, 3]] and nbins=4, the bin edges are [0, 0.75, 1.5, 2.25, 3.0] and the bars are drawn at the true bin centers 0.375, 1.125, 1.875, 2.625.
This is correct histogram geometry (and consistent with matplotlib/seaborn), but users with discrete/count data often want integer-aligned bins, i.e. edges at -0.5, 0.5, 1.5, ... so that each bar is centered on an integer value. There is currently no way to express this: nbins only accepts an int, so the only workaround is to precompute the histogram manually and pass densities directly.
Proposal
Accept a sequence of bin edges in addition to an int, mirroring np.histogram's bins parameter:
# Today (equal-width bins over [min, max]):ridgeplot(samples=samples, nbins=4)
# Proposed (custom edges, e.g. integer-aligned bins for count data):ridgeplot(samples=samples, nbins=[-0.5, 0.5, 1.5, 2.5, 3.5])
(Or via a new dedicated parameter, if overloading nbins is undesirable.)
Notes
np.histogram already supports edge sequences natively, so the change in ridgeplot._hist.bin_trace_samples should be small; most of the work is API design, typing, and docs.
Problem
When using histogram binning (
ridgeplot(samples=..., nbins=...)), the bins are alwaysnbinsequal-width bins spanning[min(samples), max(samples)](numpy's default). For discrete/count data this means bars are generally not aligned with the sample values. For example, forsamples=[[0, 1, 2, 3]]andnbins=4, the bin edges are[0, 0.75, 1.5, 2.25, 3.0]and the bars are drawn at the true bin centers0.375, 1.125, 1.875, 2.625.This is correct histogram geometry (and consistent with matplotlib/seaborn), but users with discrete/count data often want integer-aligned bins, i.e. edges at
-0.5, 0.5, 1.5, ...so that each bar is centered on an integer value. There is currently no way to express this:nbinsonly accepts anint, so the only workaround is to precompute the histogram manually and passdensitiesdirectly.Proposal
Accept a sequence of bin edges in addition to an int, mirroring
np.histogram'sbinsparameter:(Or via a new dedicated parameter, if overloading
nbinsis undesirable.)Notes
np.histogramalready supports edge sequences natively, so the change inridgeplot._hist.bin_trace_samplesshould be small; most of the work is API design, typing, and docs.ridgeplot._hist#365.