You are now following this Submission
- You will see updates in your followed content feed
- You may receive emails, depending on your communication preferences
Basic usage
% X - Group positions.
% Y - Matrix data.
X = 1:5;
Y = randn(100, 5);
violinChart(gca, X, Y, 'Width',.8);
legend()
Categorical data
X = randi([1, 5], [1, 200]);
Y = randn(1, 200) + sin(X);
hdl = violinChart(gca, X, Y, 'FaceColor',[132,158,119]./255);
% Set propertied for density patches.
CList = lines(5);
for i = 1:length(hdl.F_density)
set(hdl.F_density(i), 'LineWidth',1, 'FaceColor',CList(i, :), 'FaceAlpha',.5)
end
Overlaying two violin sets on the same axes
X1 = [1:2:7, 13];
Y1 = randn(100, 5) + sin(X1);
X2 = 2:2:10;
Y2 = randn(100, 5) + cos(X2);
figure()
violinChart(gca, X1, Y1, [0, 114, 189]./255);
violinChart(gca, X2, Y2, [217, 83, 25]./255);
legend()
ggtheme
rng(1)
X1 = [1:2:7, 13];
Y1 = randn(100, 5) + sin(X1);
X2 = 2:2:10;
Y2 = randn(100, 5) + cos(X2);
figure()
hdl1 = violinChart(gca, X1, Y1, [0, 114, 189]./255);
hdl2 = violinChart(gca, X2, Y2, [217, 83, 25]./255);
legend()
theme = 'solarized';
% ylabel(strrep(theme, '_', '\_'), 'FontSize',18)
ggThemeViolin([hdl1, hdl2], theme)
% Available themes:
% 'flat', 'flat_dark', 'camouflage', 'chalk', 'copper', 'dust',
% 'earth', 'fresh', 'grape', 'grass', 'greyscale', 'light',
% 'lilac', 'pale', 'sea', 'sky', 'solarized'
Acknowledgements:
The color palettes in this toolbox are adapted from the R package 'ggthemr'
(https://github.com/Mikata-Project/ggthemr), originally created by Ciaran Tobin
and maintained by the Mikata-Project team.
Cite As
Zhaoxu Liu / slandarer (2026). violin plot with ggtheme (https://uk.mathworks.com/matlabcentral/fileexchange/120283-violin-plot-with-ggtheme), MATLAB Central File Exchange. Retrieved .
General Information
- Version 2.0.1 (966 KB)
MATLAB Release Compatibility
- Compatible with any release
Platform Compatibility
- Windows
- macOS
- Linux
