Version (5,15 KB) von Gordon
Generate a density plot using hexagonal patches.
Aktualisiert 24 Feb 2014

Lizenz anzeigen

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.
hexscatter(xdata, ydata)
hexscatter(xdata, ydata, 'Name', Value, ...)
h = hexscatter(...)

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
'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

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

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

Also available in the Bean Matlab Toolkit:

Zitieren als

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

Kompatibilität der MATLAB-Version
Erstellt mit R2013b
Kompatibel mit allen Versionen
Windows macOS Linux
Mehr zu Polygons finden Sie in Help Center und MATLAB Answers

Inspiriert: Honeycomb

Community Treasure Hunt

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

Start Hunting!
Version Veröffentlicht Versionshinweise

Added dependencies: default_param, get_params