Scatter Plot colored by Kernel Density Estimate

Version (1.4 KB) by Nils
Scatter plot where each point is colored by the spatial density of nearby points.
Updated 15 Jan 2018

View License

The function use the kernel smoothing function to compute the probability density estimate (PDE) for each point. It uses the PDE has color for each point.
x <Nx1 double> position of markers on X axis
y <Nx1 double> posiiton of markers on Y axis
varargin can be used to send a set of instructions to the scatter function
Supports the MarkerSize parameter
Does not support the MarkerColor parameter
h returns handles to the scatter objects created
% Generate data
x = normrnd(10,1,1000,1);
y = x*3 + normrnd(10,1,1000,1);
% Plot data using probability density estimate as function
scatter_kde(x, y, 'filled', 'MarkerSize', 100);
% Add Color bar
cb = colorbar();
cb.Label.String = 'Probability density estimate';

Cite As

Nils (2024). Scatter Plot colored by Kernel Density Estimate (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2017b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes

Add figure on post