matlab输出箱线图的五个特征值,MATLAB-在箱线图上表示不同类别数据的均值

I have a boxplot with six different categories plotted. These categories have been read in from different columns of an Excel spreadsheet. I would like to display the mean of each category on its associated box. After using the boxplot function, I have:

hold on

plot(mean(data1), 'r+')

This plots the mean of the first category of data correctly. However, if I continue on with the code and do this:

hold on

plot(mean(data1), 'r+')

hold on

plot(mean(data2), 'r+')

it will plot the mean of data2 at the x-axis location of data1 instead of at the x-axis location of data2. Is there a way I can tell the program to plot each category's mean at specific x-axis locations that correspond to each category?

Here is the remainder of my code:

% create boxplots for altitudinal and areal extent for all categories

% read in altitudinal extent for all categories

% nontor

[~,~,raw] = xlsread('SupercellEnvironmentalVariables.xlsx',...

'nontornadic','C5:C48');

% find numbers

containsNumbers = cellfun(@isnumeric,raw);

% convert to string

raw(containsNumbers) =

cellfun(@num2str,raw(containsNumbers),'UniformOutput',false);

NonAltExt = str2double(raw);

% tornadic

[~,~,raw] = xlsread('SupercellEnvironmentalVariables.xlsx',...

'tornadic','C5:C78');

% find numbers

containsNumbers = cellfun(@isnumeric,raw);

% convert to string

raw(containsNumbers) =

cellfun(@num2str,raw(containsNumbers),'UniformOutput',false);

TorsAltExt = str2double(raw);

% all tornadoes

[~,~,raw] = xlsread('SupercellEnvironmentalVariables.xlsx',...

'tornadic','F5:F78');

% find numbers

containsNumbers = cellfun(@isnumeric,raw);

% convert to string

raw(containsNumbers) =

cellfun(@num2str,raw(containsNumbers),'UniformOutput',false);

all_torsAltExt = str2double(raw);

% no tornadoes

[~,~,raw] = xlsread('SupercellEnvironmentalVariables.xlsx',...

'tornadic','O5:O78');

% find numbers

containsNumbers = cellfun(@isnumeric,raw);

% convert to string

raw(containsNumbers) =

cellfun(@num2str,raw(containsNumbers),'UniformOutput',false);

notorAltExt = str2double(raw);

% weak tornadoes

[~,~,raw] = xlsread('SupercellEnvironmentalVariables.xlsx',...

'tornadic','I5:I78');

% find numbers

containsNumbers = cellfun(@isnumeric,raw);

% convert to string

raw(containsNumbers) =

cellfun(@num2str,raw(containsNumbers),'UniformOutput',false);

weakAltExt = str2double(raw);

% significant tornadoes

[~,~,raw] = xlsread('SupercellEnvironmentalVariables.xlsx',...

'tornadic','L5:L78');

% find numbers

containsNumbers = cellfun(@isnumeric,raw);

% convert to string

raw(containsNumbers) =

cellfun(@num2str,raw(containsNumbers),'UniformOutput',false);

sigAltExt = str2double(raw);

AltExt = [NonAltExt;TorsAltExt;all_torsAltExt;notorAltExt;...

weakAltExt;sigAltExt];

g = [ones(size(NonAltExt)); 2*ones(size(TorsAltExt));

3*ones(size(all_torsAltExt));...

4*ones(size(notorAltExt)); 5*ones(size(weakAltExt));

6*ones(size(sigAltExt))];

Figure1 = figure;

bh = boxplot(AltExt,g,'symbol','k*');

% patch fill each box to get a color fill with some transparency

h = findobj(gca,'Tag','Box');

for j=1:length(h)

patch(get(h(j),'XData'),get(h(j),'YData'),'y','FaceAlpha',.5,'FaceColor',[1 1 1],...

'EdgeColor',[0 0 0]);

end

hold on

plot(mean(NonAltExt),'r+')

title('Mean Z_D_R Col. Max. Altitude > 0\circC (km) for All Categories',...

'FontSize',12,'FontWeight','bold')

ylabel('Mean Z_D_R Col. Max. Altitude > 0\circC

(km)','FontSize',10,'FontWeight','bold')

set(gca, 'Ticklength', [0 0])

set(gca,'xticklabel',[{'Nontornadic','Tornadic','All Tornado Sam. Vols.',...

'No Tornado Sam. Vols.','Weak Tornado Sam. Vols.',...

'Significant Tornado Sam. Vols.'}],'XTickLabelRotation',45)

set(bh(:,:),'linewidth',1.5);

ax = gca;

ax.YGrid = 'on';

% set color and increase thickness of median lines

median_lines = findobj(gca, 'type', 'line', 'Tag', 'Median');

set(median_lines, 'LineWidth',2.5, 'Color','r');

ax.Children = ax.Children([end 1:end-1]); % allows median lines to be

plotted on top of box fill

解决方案

Try this:

hold on

plot(1,mean(data1), 'r+')

plot(2,mean(data2), 'r+')

Here I'm using the plot(x,y) syntax. If you leave X out, as you did, MATLAB assumes 1.

Also, you only need to give hold on once.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值