From data to plot

2D surface and joint density fitting

A heat map becomes a quantitative model when you fit parameters—peak centroids (x0,y0), anisotropic widths (σx,σy), orientation angle θ, and background offset—to the 2D array. Whether fitting a joint sample-density cloud (X,Y) or a measured scalar surface z=f(X,Y), every fitted parameter depends directly on bin normalization, empty-cell handling, and region-of-interest bounds.

Updated · 6 min read

On this page
  1. Joint density clouds vs scalar-field surfaces
  2. Rotated 2D Gaussian and mixture models
  3. Why binned least squares behaves differently from raw MLE
  4. Comparing Autoplot, Igor Pro, OriginPro, and SciPy
  5. 2D Joint Density and Surface Fits in Autoplot
  6. Frequently asked questions

Joint density clouds vs scalar-field surfaces

Two distinct physical datasets produce 2D maps, and mixing their normalization rules invalidates downstream parameter fits:

Map domainInputsWhat each cell holdsBuilt-in fit choices
Joint DensityPaired X,YDensity (ck/(NAk)), Probability (ck/N), or Count (ck)2D Density Fit (1–6 rotated Gaussians) or Custom Density Fit
Scalar FieldPaired X,Y,ZMean, Median, Sum, Min, Max, Std Dev, or Sample Count2D 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 Ahex=332r2). 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.

Autoplot Joint Density heat map in Viridis showing 35,000 paired samples across a smoothed 60 by 60 rectangular grid with two rotated anisotropic bivariate Gaussian modes around (-0.85, -0.50) and (+1.15, +0.80), four smooth iso-density contour levels, Position X and Position Y axes in micrometers, and a vertical Density colorbar up to 7.71E-01
A smoothed 60 × 60 rectangular Joint Density Map (Viridis with four iso-density contour levels) reveals two tilted elliptical populations centered near (-0.85, -0.50) and (+1.15, +0.80) μm before fitting Gaussian parameters.

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 Δx=x−x0 and Δy=y−y0, the rotated coordinates are:

xrot=Δxcosθ+Δysinθ,yrot=−Δxsinθ+Δycosθ

For K additive components (K=1 through 6) resting on a shared baseline offset, Autoplot (fit_gaussian_2d / fit_gaussian_mixture_2d) evaluates:

z(x,y)=offset+∑k=1KAkexp(−12[(xrot,kσx,k)2+(yrot,kσy,k)2])

Each peak optimizes six shape parameters under positivity and angle bounds (Ak≥0, σx,k>0, σy,k>0, −π≤θk≤π) 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 Ak.

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 (xi,yi,zi), 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:

  1. Resolution bias vs variance trade-off: coarse rectangular bins average out curved peaks and broaden fitted widths σx,σy 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.
  2. Minimum cell counts prevent underdetermined covariance: single-peak and custom fits require at least 20 finite binned cells after ROI filtering, while K-peak mixtures (2–6 components) require max(40,25K) cells so each 6K + 1 parameter vector stays overdetermined.
  3. 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.
  4. Empty scalar cells vs zero-count density bins: in Scalar Field mode, empty rectangular bins stay NaN and are dropped before fitting; in Joint Density mode, empty bins inside rectangular grids have Density = 0 and 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:

ToolSource inputSupported 2D modelsBest workflow fit
AutoplotJoint Density (X, Y) or Scalar Field (X, Y, Z)Rotated 1–6 Gaussian mixtures, predefined and formula custom fitsInteractive macOS density binning, ROI/contour inspection, and grid export
Igor ProImage matrices (FuncFitMD)Gauss2D plus custom Igor multi-dimensional fit functionsLegacy .pxp/.ibw image stacks and scripted FuncFitMD procedures
OriginProMatrix and XYZ sheets (nlfit2d)Built-in Gauss2D library, asymmetric 2D peaks, surface fittingWindows batch surface tables and weighted matrix fitting
SciPy / PythonNumeric arrays (curve_fit, KDE)Arbitrary least squares, exact MLE (minimize), KDECustom 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.

In Autoplot

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–800 bins) or Hexagonal (12–420 density) maps directly from X and Y (Density, Probability, or Count), with optional iso-density contours and Export Binned Data (heatmap_bin_x_*, heatmap_bin_y_*, joint_*_z_*).
  • 2D Density Fit & 2D Gaussian Surface Fit: fits 1–6 rotated anisotropic 2D Gaussians (A, x₀, y₀, σx, σy, θ, offset, ± standard errors, and R²) using bounded scipy.optimize.curve_fit, displaying center markers (+), semi-transparent fitted surfaces, and Sigma (1σ,2σ,...), Fraction of Peak, or explicit Z Value contours across ROI bounds.
  • Custom Density Fit & Custom Surface Fit: fits Gaussian Peak, Lorentzian Peak, Mexican Hat, Double Gaussian Peaks, Triple Gaussian Peaks, or any vectorized z(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 reusable Derived Functions (Export Fit Function). Because fits operate strictly on finite binned cell centers (Use ROI post-binning and Export Fit Surface over the full variable range without ROI clipping), unbinned mixture clustering (EM) and Poisson-count MLE require a custom Python script via the AI Assistant.

See features and pricing.

Frequently asked questions

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 (Arect or Ahex). 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.

Try it on your own data.

Autoplot bins paired XY clouds into Joint Density maps and fits rotated 2D Gaussians, multi-peak mixtures, or custom z(x, y) surfaces locally on Apple silicon with live contours and grid exports. Part of Plus (free for 30 days).

Read how to make a scientific heat map →
Download .dmg

Without Private Cloud Compute · macOS 15–26

Apple silicon · macOS 15 or later · Free plan · Plus free for 30 days · 11 starter AI credits

Send to my Mac

Autoplot runs on a Mac. Send the link to yourself, or open it in the Mac App Store.