小提琴图(Violin Plot)可用于展示多组数据的分布状态和概率密度。
出自论文-J2020-Drought hazard transferability from meteorological to hydrological propagation
成图如下:
MATLAB代码如下:
clc
close all
clear
%% 函数说明-绘制小提琴图
pathFigure= '.\Figures\' ;
figureUnits = 'centimeters';
figureWidth = 20;
figureHeight = 10;
X1=[1:2:7,13];
Y1=randn(100,5)+sin(X1);
X2=2:2:10;
Y2=randn(100,5)+cos(X2);
figure(1)
set(gcf, 'Units', figureUnits, 'Position', [0 0 figureWidth figureHeight]);
hold on;box on;grid off;
Hdl1 = violinChart(gca,X1,Y1,[59 125 183]/255);
Hdl2 = violinChart(gca,X2,Y2,[126,15,4]/255);
% 设置其余坐标区属性
set(gca,'FontName','Times New Roman','FontSize',14,'FontWeight','bold',...
'Layer','top','LineWidth',1);
xlabel('Column' ,'Fontname', 'Times New Roman','Fontsize',16)
ylabel('Value' ,'Fontname', 'Times New Roman','Fontsize',16)
set(gca,'XLim',[0 14],'XTick', [ 2 :2: 15],'XTickLabel',[ 2 :2: 15],...
'FontSize',14,'Fontname', 'Times New Roman');
set(gca,'YLim',[-6 6],...
'YTick', [ -6 :3: 6 ],'YTickLabel', -6 :3: 6 ,...
'FontSize',14,'Fontname', 'Times New Roman');
set(gca,'TickDir','in'); % 设置坐标轴刻度朝内
hl = legend([Hdl1.F_legend,Hdl2.F_legend],{'randn+sin(x)','randn+cos(x)'});
set(hl,'Box','off','Location','NorthOutside','NumColumns',2,'FontSize',14,'FontName','Times New Roman');
str= strcat(pathFigure, "图1 "+"小提琴图", '.tiff');
print(gcf, '-dtiff', '-r600', str);
1、知乎-如何使用MATLAB绘制小提琴图