hexscatter.m

Version 1.1.0.0 (5.15 KB) by Gordon
Generate a density plot using hexagonal patches.
1.4K Downloads
Updated 24 Feb 2014

View License

When the number of elements in a scatter plot is large, the plot becomes saturated, and the true shape of the data becomes obscured. One solution is to use a density plot, where the intensity of colored patches indicates the number of points falling withing 2D bins.
HEXSCATTER generates a density plot using hexagonal bins. Hexagonal bins are often preferred over square bins because they better maintain the original look and feel of a scatter plot, as opposed to looking like a heatmap.
Syntax
hexscatter(xdata, ydata)
hexscatter(xdata, ydata, 'Name', Value, ...)
h = hexscatter(...)

Description
hexscatter(xdata, ydata) creates a density plot of the ydata versus the
xdata using hexagonal tiles. xdata and ydata should be vectors. NaN
values (and their corresponding values in the other vector) are ignored.

hexscatter(xdata, ydata, 'Name', Value, ...) accepts name-value pairs of
arguments from the following list (defaults in {}):
'xlim' { [min(xdadta(:) max(xdata(:))] } - a 2-element vector containing
the lower and upper bounds of the 2nd dimension of the grid.
'ylim' { [min(ydadta(:) max(ydata(:))] } - a 2-element vector containing
the lower and upper bounds of the 1st dimension of the grid.
'res' { 50 } - the resolution, or number of bins in each dimension. The
total number of bins will be the resolution squared.
'drawEdges' { false } - if true, edges are drawn around each hexagonal
patch.
'showZeros' { false } - if true, bins with 0 counts are shaded; if
false, only bins with non-zero counts are colored.

h = hexscatter( ... ) returns the object handle to the patch object
created.

Examples
hexscatter(rand(2000,1), rand(2000,1))

hexscatter(rand(2000,1), rand(2000,1), 'res', 90)

Also available in the Bean Matlab Toolkit:
https://github.com/brazilbean/bean-matlab-toolkit

Cite As

Gordon (2024). hexscatter.m (https://www.mathworks.com/matlabcentral/fileexchange/45639-hexscatter-m), MATLAB Central File Exchange. Retrieved .

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

Inspired: Honeycomb

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes
1.1.0.0

Added dependencies: default_param, get_params

1.0.0.0