On this page
Joint density clouds vs scalar-field surfaces
Two distinct physical datasets produce 2D maps, and mixing their normalization rules invalidates downstream parameter fits:
| Map domain | Inputs | What each cell holds | Built-in fit choices |
|---|---|---|---|
Joint Density | Paired | Density (), Probability (), or Count () | 2D Density Fit (1–6 rotated Gaussians) or Custom Density Fit |
Scalar Field | Paired | Mean, Median, Sum, Min, Max, Std Dev, or Sample Count | 2D Gaussian Surface Fit (1–6 peaks) or Custom Surface Fit |
Always use Density normalization when comparing Joint Density fits across different grid resolutions or between Rectangular cells and Hexagonal cells (where hex cell area equals ). Because Probability and Count scale with cell area, doubling grid resolution drops raw counts per bin by roughly four even though the underlying probability density is unchanged. For basic 2D binning choices before fitting, start with how to make a scientific heat map.
Rotated 2D Gaussian and mixture models
When two measurements co-vary inside a beam profile, single-molecule localization halo, or dual-parameter resonance, the principal axes of the distribution tilt at an angle relative to the plot axes. Writing local offsets and , the rotated coordinates are:
For additive components ( through 6) resting on a shared baseline offset, Autoplot (fit_gaussian_2d / fit_gaussian_mixture_2d) evaluates:
Each peak optimizes six shape parameters under positivity and angle bounds (, , , ) using bounded Trust Region Reflective least squares (scipy.optimize.curve_fit, Branch et al. 1999). Just as with 1D multi-peak fitting and peak deconvolution, multi-component mixtures are seeded from separated high-weight density peaks (cKDTree spacing check) and ordered by descending amplitude .
When the underlying peak is non-Gaussian—such as a heavy-tailed 2D Lorentzian resonance or radially symmetric Mexican Hat wavelet—switch to Custom Density Fit or Custom Surface Fit, which expose predefined templates (Gaussian Peak, Lorentzian Peak, Mexican Hat, Double Gaussian Peaks, Triple Gaussian Peaks) alongside arbitrary vectorized z(x, y) expressions over x, y, exp, log, log10, sqrt, abs, sin, and cos.
Why binned least squares behaves differently from raw MLE
Every 2D heat-map fitter operates on finite binned cell centers , never directly on unbinned scatter samples. That architectural design has four consequences verified by Scott (1979) and Cheezum et al. (2001) in particle-tracking benchmarks:
- Resolution bias vs variance trade-off: coarse rectangular bins average out curved peaks and broaden fitted widths downward in amplitude (Sheppard's broadening), whereas overly fine grids leave zero-count holes or single-sample Poisson spikes. Check your fit at two nearby resolutions—see histogram bin width for density-grid stability tests.
- Minimum cell counts prevent underdetermined covariance: single-peak and custom fits require at least
20finite binned cells after ROI filtering, while -peak mixtures (2–6components) require cells so each6K + 1parameter vector stays overdetermined. - ROI filters cell centers post-binning: enabling
Use ROI(xmin,xmax,ymin,ymax) restricts the fitted array to cells inside the box without re-binning the full domain, letting you isolate one sub-population inside a crowded multimodal cloud cleanly. - Empty scalar cells vs zero-count density bins: in
Scalar Fieldmode, empty rectangular bins stayNaNand are dropped before fitting; inJoint Densitymode, empty bins inside rectangular grids haveDensity = 0and still anchor the outer background tails (offset).
Comparing Autoplot, Igor Pro, OriginPro, and SciPy
Choose the 2D fitting workflow that matches whether you need interactive density exploration, matrix batching, or custom Poisson maximum likelihood:
| Tool | Source input | Supported 2D models | Best workflow fit |
|---|---|---|---|
| Autoplot | Joint Density (X, Y) or Scalar Field (X, Y, Z) | Rotated 1–6 Gaussian mixtures, predefined and formula custom fits | Interactive macOS density binning, ROI/contour inspection, and grid export |
| Igor Pro | Image matrices (FuncFitMD) | Gauss2D plus custom Igor multi-dimensional fit functions | Legacy .pxp/.ibw image stacks and scripted FuncFitMD procedures |
| OriginPro | Matrix and XYZ sheets (nlfit2d) | Built-in Gauss2D library, asymmetric 2D peaks, surface fitting | Windows batch surface tables and weighted matrix fitting |
| SciPy / Python | Numeric arrays (curve_fit, KDE) | Arbitrary least squares, exact MLE (minimize), KDE | Custom Poisson-likelihood localization or unbinned mixtures (GaussianMixture) |
Keep custom Python / SciPy pipelines when sub-pixel single-molecule localization needs Poisson maximum likelihood rather than binned least squares (Cheezum et al. 2001) or when unbinned expectation–maximization (scikit-learn GaussianMixture) is preferable to gridded histograms. Use Autoplot when you want instant switching between Rectangular/Hexagonal bins, 2D Density Fit, 2D Gaussian Surface Fit, live contour levels, and exported surface grids without writing solver boilerplate. For general solver bounds and non-identifiability checks in custom formulas, see nonlinear curve fitting.
2D Joint Density and Surface Fits in Autoplot
In any Heat Map figure (Layers → Run Analysis), Autoplot runs five native 2D density and fitting analyses locally on Apple silicon (Plus — free for 30 days):
- Joint Density Map: builds
Rectangular(10–800bins) orHexagonal(12–420density) maps directly fromXandY(Density,Probability, orCount), with optional iso-density contours andExport Binned Data(heatmap_bin_x_*,heatmap_bin_y_*,joint_*_z_*). - 2D Density Fit & 2D Gaussian Surface Fit: fits
1–6rotated anisotropic 2D Gaussians (A,x₀,y₀,σx,σy,θ,offset,±standard errors, andR²) using boundedscipy.optimize.curve_fit, displaying center markers (+), semi-transparent fitted surfaces, andSigma (1σ,2σ,...),Fraction of Peak, or explicitZ Valuecontours acrossROIbounds. - Custom Density Fit & Custom Surface Fit: fits
Gaussian Peak,Lorentzian Peak,Mexican Hat,Double Gaussian Peaks,Triple Gaussian Peaks, or any vectorizedz(x, y)expression with user initial guesses (amp=...,x0=...,y0=...) and automatic positivity/angle constraints on sigma- and theta-named parameters. - Exports & where it stops: export gridded evaluations (
Export Fit Surface), sample-coordinate predictions (Save Z at Samples), or reusableDerived Functions(Export Fit Function). Because fits operate strictly on finite binned cell centers (Use ROIpost-binning andExport Fit Surfaceover the full variable range without ROI clipping), unbinned mixture clustering (EM) and Poisson-count MLE require a custom Python script via the AI Assistant.
Frequently asked questions
| When should I pick 2D Density Fit vs 2D Gaussian Surface Fit? | Use 2D Density Fit when you only have paired (X, Y) coordinates and want to model event concentration per unit area; use 2D Gaussian Surface Fit when each (X, Y) location also carries a measured scalar response Z aggregated per cell (Mean, Median, Sum, Max, or Sample Count). |
|---|---|
| Why does changing bin resolution change my fitted amplitude in Probability or Count mode? | Raw Count and Probability bin totals grow proportionally with bin area, whereas Density divides by both total sample count and cell area ( or ). Keep Density selected whenever fitting or comparing joint distributions across grid sizes or between rectangular and hexagonal bins. |
| Does Use ROI re-bin my data inside the selected rectangle? | No. Autoplot generates the source grid first, converts cell centers back to data coordinates, and filters cells against [xmin, xmax, ymin, ymax] before fitting. Likewise, Export Fit Surface evaluates the fitted function across the full X/Y variable domain rather than clipping to ROI bounds. |
| How many points do 2D Gaussian and mixture fits require? | Single-peak (Peaks = 1) and custom 2D fits require at least 20 finite binned cells inside the fit domain (ROI applied), while multi-peak Gaussian mixtures (Peaks = 2 to 6) require at least max(40, 25 * Peaks) finite binned cells. |
Sources
Algorithm details (fit_gaussian_2d, fit_gaussian_mixture_2d, cKDTree mixture center seeding, 20 and max(40, 25 * Peaks) cell minimums, rotated coordinate transformation x_rot / y_rot, Use ROI post-binning filtering, Density/Probability/Count scaling, and HeatMapPredefinedDist2D) and UI labels (Joint Density Map, 2D Density Fit, 2D Gaussian Surface Fit, Custom Density Fit, Custom Surface Fit, Export Fit Surface, Save Z at Samples, Export Fit Function) were verified directly against Autoplot source (math_logic.py, DataModel.swift, HeatMapFitResult.swift, HeatMapView.swift, and docs/user-wiki/run-analysis/heat-*.md / algorithms/heat-map-fits.md) on 28 November 2026. Bounded nonlinear least-squares optimization uses SciPy's scipy.optimize.curve_fit and Trust Region Reflective step theory from M. A. Branch, T. F. Coleman, and Y. Li, "A Subspace, Interior, and Conjugate Gradient Method for Large-Scale Bound-Constrained Minimization Problems," SIAM Journal on Scientific Computing 21(1), 1–23 (1999), DOI 10.1137/S1064827595289108; binned density width selection draws on D. W. Scott, "On optimal and data-based histograms," Biometrika 66(3), 605–610 (1979), DOI 10.1093/biomet/66.3.605; and 2D Gaussian localization accuracy vs binned grid bias draws on M. K. Cheezum, W. F. Walker, and W. H. Guilford, "Quantitative Comparison of Algorithms for Tracking Single Fluorescent Particles," Biophysical Journal 81(4), 2378–2388 (2001), DOI 10.1016/S0006-3495(01)75884-5.