scatterhist
statistics: scatterhist (x, y)
statistics: scatterhist (x, y, name, value, …)
statistics: h = scatterhist (…)
Create a scatter plot of x and y with marginal histograms.
scatterhist (x, y) draws a scatter plot of the vectors
x and y in a central set of axes, with a histogram of x
above it and a histogram of y to its right. x and y must
be vectors of the same length; NaN values are removed pairwise from
the scatter plot and individually from each marginal histogram.
The following name/value pairs are accepted:
"Group""NBins"[nx ny]. The default is chosen by Scott’s
rule."Kernel""off" (default) draws histograms for the marginals; "on" or
"overlay" draws kernel density estimates instead."Location""SouthWest" (default), "SouthEast", "NorthEast", or
"NorthWest"."Legend""on" or "off" to show or hide the group legend. The default
is "on" when a grouping variable is supplied."Marker", "MarkerSize"The optional output h is a three-element vector of axes handles: the central scatter axes, the axes of the x (horizontal) histogram, and the axes of the y (vertical) histogram.
The y histogram’s axes is built differently from MATLAB’s and its
properties read accordingly. We plot that marginal transposed, so its
"XLim" is the density and "XDir" carries the bar direction.
MATLAB plots it like the x one – data along "XLim", density
along "YLim" – and rotates the whole axes by setting
"View" to [270, 90], so there the direction is carried by
"YDir" and "XDir" is always "normal". The picture
is the same; code reading those properties off h(3) is not
portable between the two.
'Parent' draws into a supplied figure or uipanel instead of the
current figure. The container is used as it stands and is never
cleared, so a scatterhist can be placed alongside other axes.
'Location' names the corner the marginal histograms occupy,
'SouthWest' by default, or 'SouthEast', 'NorthEast'
or 'NorthWest'; the scatter takes the opposite corner. With the
default the histograms are drawn below and to the left of the scatter.
'Direction' points the marginal bars toward the scatter plot,
'in' by default, or away from it with 'out', whichever side
'Location' has placed them on.
'PlotGroup' draws one marginal per group with 'on', or a
single pooled marginal with 'off'. It defaults to 'on' when
'Group' is given and to 'off' otherwise.
'Style' outlines the marginals as 'bar' or 'stairs',
defaulting to stairs when the data are grouped and bars when they are not.
'Color' sets the group colours, either as a character vector of
colour names or as an -by-3 matrix of RGB values, cycled over the
groups.
'LineStyle' and 'LineWidth' style the marginal outlines, not
the scatter markers, and are cycled over the groups.
'Bandwidth' sets the kernel bandwidth used when 'Kernel' is
on: a scalar for all marginals, a pair for x and y, or one row
per group.
See also: gscatter, scatter, hist, ksdensity
Source Code: scatterhist
Scatter plot of two iris measurements with marginal histograms by species.
load fisheriris; scatterhist (meas(:,1), meas(:,2), "Group", species);
Marginal kernel density estimates instead of histograms.
load fisheriris; scatterhist (meas(:,3), meas(:,4), "Group", species, "Kernel", "on");