swarmchart3
Syntax
Description
Vector Data
swarmchart3(
displays a 3-D swarm chart, which is a scatter plot with the points offset (jittered) in
the x
,y
,z
)x
- and y
-dimensions. The points form distinct
shapes, and the outline of each shape is similar to a violin plot. 3-D swarm charts help
you to visualize discrete (x
,y
) data with the
distribution of the z data. At each
(x
,y
) location, the points are jittered based on
the kernel density estimate of z
.
swarmchart3(
specifies the marker colors. To plot all the markers with the same color, specify
x
,y
,z
,sz
,c
)c
as a color name or an RGB triplet. To assign a different color to
each marker, specify a vector the same size as x
, y
,
and z
. Alternatively, you can specify a three-column matrix of RGB
triplets. The number of rows in the matrix must match the length of x
,
y
, and z
.
swarmchart3(___,
specifies a
different marker than the default marker, which is a circle. Specify
mkr
)mkr
after all the arguments in any of the previous syntaxes.
Table Data
swarmchart3(
plots the variables tbl
,xvar
,yvar
,zvar
)xvar
, yvar
, and
zvar
from the table tbl
. To plot one data set,
specify one variable each for xvar
, yvar
, and
zvar
. To plot multiple data sets, specify multiple variables for at
least one of those arguments. The arguments that specify multiple variables must specify
the same number of variables.
Additional Options
swarmchart3(
displays the
swarm chart in the target axes. Specify the axes before all the arguments in any of the
previous syntaxes.ax
,___)
swarmchart3(___,
specifies additional properties for the swarm chart using one or more
Name,Value
)Name,Value
arguments. For example:
swarmchart3(x,y,z,'LineWidth',2)
creates a swarm chart with 2-point marker outlines.swarmchart3(tbl,'MyX','MyY','MyZ','ColorVariable','MyColors')
creates a swarm chart from data in a table, and customizes the marker colors using data from the table.
For a list of properties, see Scatter Properties.
s = swarmchart3(___)
returns the
Scatter
object. Use s
to modify properties of the
chart after creating it. For a list of properties, see Scatter Properties.
Examples
Input Arguments
Name-Value Arguments
Algorithms
The points in a swarm chart are jittered using uniform random values that are weighted by
the Gaussian kernel density estimate of z
and the relative number of points
at each (x
, y
) location. This behavior corresponds to
the default 'density'
setting of the XJitter
and
YJitter
properties on the Scatter
object when you call
the swarmchart3
function.
The maximum spread of points at each x
location is 90% of the smallest distance between adjacent points by default. For example, in
the x
dimension, the spread is calculated
as:
spread = 0.9 * min(diff(unique(x)));
You can control the offset by setting the XJitterWidth
and
YJitterWidth
properties on the Scatter
object.