【MATLAB基础绘图第18棒】绘制箱型图

箱型图(Boxplots)

案例1:基本绘制

如下图(出自论文-J2018-Meteorological and Hydrological Drought on the Loess Plateau, China Evolutionary Characteristics, Impact, and Propagation)
在这里插入图片描述
图形如下:

相应MATLAB代码如下:

案例2:设置不同填充色

如下图(出自论文-J2016-From meteorological to hydrological drought using standardised indicators):
在这里插入图片描述
图形如下:
在这里插入图片描述
相应MATLAB代码如下:

clc
close all
clear
%% 函数说明-绘制各类箱型图pairboxplot

pathFigure= '.\Figures\' ;

%% 开始绘图
% ==========================================================

% 随机构造一组数据
PntSet1=sort(mvnrnd(0,2,25));
PntSet2=sort(mvnrnd(.5,2.5,25));
PntSet3=sort(mvnrnd(0,2,25));
PntSet4=sort(mvnrnd(.5,2.5,25));
PntSet5=sort(mvnrnd(.6,2.5,25));
% Y=[PntSet1,PntSet2];
Y=[PntSet1,PntSet2,PntSet3,PntSet4,PntSet5];

% 配色列表
C1=[59 125 183;244 146 121;242 166 31;180 68 108;220 211 30]./255;
C2=[102,173,194;36,59,66;232,69,69;194,148,102;54,43,33]./255;
C3=[38,140,209;219,51,46;41,161,153;181,138,0;107,112,196]./255;
C4=[110,153,89;230,201,41;79,79,54;245,245,245;199,204,158]./255;
C5=[235,75,55;77,186,216;2,162,136;58,84,141;245,155,122]./255;
C6=[23,23,23;121,17,36;44,9,75;31,80,91;61,36,42]./255;
C7=[126,15,4;122,117,119;255,163,25;135,146,73;30,93,134]./255;
colorList=C7;


% 绘图
boxplot(Y,'Symbol','o','OutlierSize',3,'Colors',[0,0,0]);

% 坐标区域属性设置
ax=gca;hold on;
ax.LineWidth=1.1;
ax.FontSize=12;
ax.FontName='Times New Roman';
ax.XTickLabel={'AA','BB','CC','DD','EE','FF'};
ax.Title.String='Title of Paired BoxPlot';
ax.Title.FontSize=14;
ax.YLabel.String='expression of XXX';

% 修改线条粗细
lineObj=findobj(gca,'Type','Line');
for i=1:length(lineObj)
    lineObj(i).LineWidth=1;
    lineObj(i).MarkerFaceColor=[1,1,1].*.3;
    lineObj(i).MarkerEdgeColor=[1,1,1].*.3;
end

% 为箱线图的框上色
boxObj=findobj(gca,'Tag','Box');
for i=1:length(boxObj)
    patch(boxObj(i).XData,boxObj(i).YData,colorList(length(boxObj)+1-i,:),'FaceAlpha',0.5,...
        'LineWidth',1.1);
end

% 导出图形
str= strcat(pathFigure, "图1 "+"箱型图", '.tiff');
print(gcf, '-dtiff', '-r600', str);

案例3:设置背景不同填充色

如下图(出自论文-J2021-Spatial and temporal patterns of propagation from meteorological to hydrological droughts in Brazil):
在这里插入图片描述
图形如下:

相应MATLAB代码如下:

参考

1、知乎MATLAB | 好看的配对箱线图绘制模板

  • 7
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

WW、forever

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值