Skip to content

FEA: Add histograms, 2D histograms and density contours - #170

Merged
thclark merged 2 commits into
bars-and-histogramsfrom
histograms-on-bars
Oct 26, 2026
Merged

thclark merged 2 commits into
bars-and-histogramsfrom
histograms-on-bars

Conversation

@thclark

@thclark thclark commented Oct 26, 2026

Copy link
Copy Markdown
Owner

Stage 5 of the bars and histograms epic. It delivers the histogram (#93) and the 2D histogram (#94).

Binning

The binning module provides:

  • bin counts, widths, explicit edges and the rules Auto, Sturges, Scott, Freedman–Diaconis, Sqrt and Integers;
  • explicit ranges and weights;
  • seven normalisations.

It follows numpy 2.3, and its tests cite the numpy call for each expected value. It uses the model's Bins, BinRule and HistNorm. Non-finite and out-of-range samples are excluded and reported. A bad bin specification never panics; it draws nothing and is reported by the handle's error().

Facade calls

  • hist draws touching bars, or stairs for the step and filled-step styles.
  • hists draws stacked or grouped histograms of several samples on shared bins, using the same placement code as bars.
  • hist_counts draws pre-binned counts.
  • hist2d draws cells, with its counts stored so that colour-scale limits and colourbars work.
  • density_contour draws a contour on the bin centres, with the contour artist unchanged.

Stored records (ADR 0029)

Each histogram stores a record of how it was binned: the bins as given, the resolved edges, the range, the normalisation, the total and the exclusions. Datatips read each whole bin's count and density from the record, including for grouped members.

Documentation

The getting-started guide gains a Histograms section, and the equivalent-functions reference and the figure schema are updated.

Existing gallery figures render byte-identically.

Add the binning module with numpy's bin rules and edge semantics, MATLAB's integers rule and normalisations, weights, explicit ranges and a summary of excluded samples, in one and two dimensions.
Add hist, hists, hist_counts, hist2d and density_contour to the facade.
Bin samples with the binning module, which now takes the bin types of
the model, and store bars, stairs or cells with a record of how they
were binned, including the resolved bin edges, so that datatips read
the count and density of a whole bin. Share the placement of grouped
and stacked columns between the bars and hists helpers.
@thclark
thclark merged commit 8419b2c into bars-and-histograms Oct 26, 2026
7 checks passed
thclark added a commit that referenced this pull request Oct 26, 2026
* FEA: Add histogram binning rules and normalisations

Add the binning module with numpy's bin rules and edge semantics, MATLAB's integers rule and normalisations, weights, explicit ranges and a summary of excluded samples, in one and two dimensions.

* FEA: Add histograms, 2D histograms and density contours

Add hist, hists, hist_counts, hist2d and density_contour to the facade.
Bin samples with the binning module, which now takes the bin types of
the model, and store bars, stairs or cells with a record of how they
were binned, including the resolved bin edges, so that datatips read
the count and density of a whole bin. Share the placement of grouped
and stacked columns between the bars and hists helpers.
@thclark
thclark deleted the histograms-on-bars branch October 26, 2026 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant