violin
statistics: violin (x)
statistics: h = violin (x)
statistics: h = violin (…, property, value, …)
statistics: h = violin (hax, …)
statistics: h = violin (…, "horizontal")
Produce a Violin plot of the data x.
The input data x can be a N-by-m array containing N observations of m variables. It can also be a cell with m elements, for the case in which the variables are not uniformly sampled.
The following property can be set using property/value pairs (default values in parenthesis). The value of the property can be a scalar indicating that it applies to all the variables in the data. It can also be a cell/array, indicating the property for each variable. In this case it should have m columns (as many as variables).
hist to compute the histogram
of the data. This property indicates how many bins to use.
See help hist for more details.sqp).
The result is in general very noisy. To smooth the result the bandwidth is
multiplied by the value of this property. The higher the value the smoother
the violins, but values too high might remove features from the data
distribution.If the string "Horizontal" is among the input arguments, the violin plot is rendered along the x axis with the variables in the y axis.
The returned structure h has handles to the plot elements, allowing customization of the visualization using set/get functions.
Example:
title ("Grade 3 heights");
axis ([0,3]);
set (gca, "xtick", 1:2, "xticklabel", {"girls"; "boys"});
h = violin ({randn(100,1)*5+140, randn(130,1)*8+135}, "Nbins", 10);
set (h.violin, "linewidth", 2)
|
See also: boxplot, hist
Source Code: violin
clf
x = zeros (9e2, 10);
for i=1:10
x(:,i) = (0.1 * randn (3e2, 3) * (randn (3,1) + 1) + 2 * randn (1,3))(:);
endfor
h = violin (x, 'color', 'c');
axis tight
set (h.violin, 'linewidth', 2);
set (gca, 'xgrid', 'on');
xlabel ('Variables')
ylabel ('Values')
clf
data = {randn(100,1)*5+140, randn(130,1)*8+135};
subplot (1,2,1)
title ('Grade 3 heights - vertical');
set (gca, 'xtick', 1:2, 'xticklabel', {'girls'; 'boys'});
violin (data, 'Nbins', 10);
axis tight
subplot (1,2,2)
title ('Grade 3 heights - horizontal');
set (gca, 'ytick', 1:2, 'yticklabel', {'girls'; 'boys'});
violin (data, 'horizontal', 'Nbins', 10);
axis tight
clf
data = exprnd (0.1, 500,4);
violin (data, 'nbins', {5,10,50,100});
axis ([0 5 0 max(data(:))])
clf data = exprnd (0.1, 500,4); violin (data, 'color', jet (4)); axis ([0 5 0 max(data(:))])
clf data = repmat (exprnd (0.1, 500,1), 1, 4); violin (data, 'width', linspace (0.1,0.5,4)); axis ([0 5 0 max(data(:))])
clf data = repmat (exprnd (0.1, 500,1), 1, 4); violin (data, 'nbins', [5,10,50,100], 'smoothfactor', [4 4 8 10]); axis ([0 5 0 max(data(:))])