Marginal distributions are summary plots (strips) displayed alongside the main plot. The marginals prop is a layered API that can be configured per side (top, right, bottom, left).
Supported Built-in Types
histogramkde (Kernel Density Estimation)cdf (Cumulative Distribution Function)rug
Configuration Options
For each side, you can pass an object to control:
type: The distribution type (e.g., 'histogram').per_series: Boolean. If true, shows one curve per series; if false, shows one merged curve.placement: Where the strip sits relative to the axis. Options: 'auto', 'flush', or 'outer'.size: The size of the marginal strip.bins: (For histograms) Number of bins.bandwidth: (For KDE) Use 'silverman', 'scott', or a specific number.curve: (For KDE) The interpolation curve.normalize: (For histograms) 'count', 'density', or 'probability'.axis: Bind to a secondary axis ('x2' or 'y2').data: Provide external data via number[] or a function (ctx) => number[].reduce: Compute a bespoke curve via (values, weights, ctx) => MarginalCurve.
Custom Marginal Snippets
If built-ins are insufficient, use the snippet key to provide a custom Svelte snippet. The snippet receives a context object: { rect, positional_scale, value_scale, baseline, curves, series }.
<ScatterPlot
{series}
marginals={{
top: { type: 'histogram', bins: 40, fill: '#0ca678', normalize: 'density' },
right: { type: 'kde', bandwidth: 'scott', curve: 'natural' },
}}
/>